You're telling your list view that you want to use adapter2
, and then telling it you want to use adapter
- it can only read data from one adapter at a time.
If you want to display data from two lists, you could do something like this.
First, combine your two lists into a class, and build a List<Post>
of these, instead of having two arrays:
public class Post {
String mName, mComment;
public Post(String name, String comment) {
mName = name;
mComment = comment;
}
public String getName() {
return mName;
}
public String getComment() {
return mComment;
}
}
Then, write an adapter that knows how to display Post
items:
public class PostAdapter extends BaseAdapter {
private Activity mActivity;
private List<Post> mPosts;
public TweetstreamAdapter(Activity activity, List<Post> posts) {
mActivity = activity;
mPosts = posts;
}
@Override
public int getCount() {
return mPosts.size();
}
@Override
public Post getItem(int position) {
return mPosts.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Post post = getItem(position);
if (convertView == null) {
convertView = mActivity.getLayoutInflater().inflate(R.layout.listlook, parent, false);
}
((TextView)convertView.findViewById(R.id.txtl1)).setText(post.getName());
((TextView)convertView.findViewById(R.id.txtl2)).setText(post.getComment());
return convertView;
}
}
Then in your activity, you set the adapter like this:
setListAdapter(new PostAdapter(this, posts));
where posts
is a List<Post>
of posts.
Note: You'll need to ensure you have Updated to match your id's. This should just drop in, provided you construct a list of TextView
entries in your listlook
layout that have IDs that match those that the adapter is searching for. Update the code to match your IDs accordingly.Post
objects correctly.
Update 2: You could build a list like this, assuming the two arrays (names/comments) are the same length:
List<Post> posts = new ArrayList<Post>();
for(int i = 0; i < names.length; i++) {
posts.add(new Post(names[i], comments[i]);
}