Reputation: 181
I have a custom ListView
with two TextViews
, I have two string arrays in my class how can I add these two string arrays as items for my ListView
? Each representing one textview.
Thank you.
Upvotes: 0
Views: 2228
Reputation: 2936
i think this is useful to you , call simple adapter with two string array
public class simleAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater linflater;
private TextView txt_1, txt_2;
private String[] str1;
private String[] str2;
public simleAdapter(Context context, String[] s1, String[] s2) {
mContext = context;
str1 = s1;
str2 = s2;
linflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return str1.length;
}
@Override
public Object getItem(int arg0) {
return str1[arg0];
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = linflater.inflate(R.layout.feed_raw, null);
}
txt_1 = (TextView) convertView.findViewById(R.id.txtlist1);
txt_2 = (TextView) convertView.findViewById(R.id.txtlist2);
txt_1.setText(str1[position]);
txt_2.setText(str2[position]);
return convertView;
}
}
let me know if you have any doubt here
Upvotes: 1
Reputation: 5969
Check my answer in this thread Custom adapter: get item number of clicked item in inflated listview. That should answer what you are trying to do.
Upvotes: 0