is it possible to set adapter to linear layout?

shashi2459 picture shashi2459 · Jul 23, 2014 · Viewed 20.3k times · Source

Is it possible to set adapter to a LinearLayout?

I don't want to use ListView since I am using ScrollView. so I am using LinearLayout...

In that I am dynamically adding views and now I need to use adapter.. so anybody have any suggestions?

I am doing this...

LinearLayout clientList = (LinearLayout) findViewById(R.id.clients);
adapter = new Sample1AdapterActivity(this, arrayList);
View list = (ListView) getLayoutInflater().inflate(R.layout.user_details, getListView(), false);

Answer

Blackbelt picture Blackbelt · Jul 23, 2014

no you can't. What you can do is inflate the single row, and adding to the LinearLayout. In pseudo code:

  LinearLayout linearLayout = (LinearLayout) findViewById(...);
  LayoutInflater inflater = LayoutInflater.from(this);
  for (item in arrayList) {
     View view  = inflater.inflate(R.layout.row, linearLayout, false); 
     // set item content in view
     linearLayout.addView(view)
  }