Sarmad Aijaz Sarmad Aijaz - 22 days ago 5
Java Question

I want two listviews to scroll at the same time

I have an activity in which I have two listviews.

One is custom listview with imageview and textview insdie and another one will be a button after I find solution of scrolling.

Basically left is a list for food and its picture and right side is list for buying it.

Now I have problem in scrolling them at same time.

public class list_activity extends AppCompatActivity {

String[] itemname ={
"UC Browser",
"Android Folder",
"VLC Player",
"Cold War",
String[] buy={"one","two","two","two","two","two","two","two","two","two","two","two","two","two","two","two","two"};
Context context = this;

protected void onCreate(Bundle savedInstanceState) {
ListAdapter adapter = new com.example.azaabudeen.restoapp.CustomListView(this,itemname);
ListView listView= (ListView)findViewById(;
ListView secondlistview= (ListView)findViewById(;
ListAdapter secondA= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,buy);

final Dialog dialog = new Dialog(context);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String currentItem= String.valueOf(parent.getItemAtPosition(position));

/// final TextView text = (TextView)findViewById(;
/// final Button myButton=(Button)findViewById(;
/// text.setText("Image of the list");
/// myButton.setOnClickListener(new View.OnClickListener() {
/// @Override
/// public void onClick(View v) {
//// dialog.dismiss();
// }
/// });;


I did it by individually adding onClickListners to Customadapter
here is the code

class CustomListView extends ArrayAdapter {
public CustomListView(Context context, String[] resource) {
super(context,R.layout.custom_view , resource);

public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater MyInflater = LayoutInflater.from(getContext());
View CustomView = MyInflater.inflate(R.layout.custom_view, parent, false);
String SingleItem= (String) getItem(position);
TextView text =(TextView)CustomView.findViewById(;
ImageView Image= (ImageView)CustomView.findViewById(;

final Button Buybutton= (Button)CustomView.findViewById(;
Buybutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getContext(), "Bought", Toast.LENGTH_SHORT).show();

Image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

return CustomView;


You should just use one ListView.

You can set onClickListener inside your custom Adapter.

An example is here: ListView with clickListener

Set onClickListener for your imageView and for your button.