我想使用类似于此的BaseAdapter
方法:
public void onClick() {
Intent intent = new Intent(this, ChatActivity.class).putExtra(chatroomName)
//Putting the text in the listview into the intent
startActivity(intent)
}
有办法做到这一点吗?
以下是适配器的内容:
chat.setAdapter(new BaseAdapter() {
@Override
public int getCount() {
return messages.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
}
Date d = new Date();
TextView seeTexts = (TextView) convertView.findViewById(android.R.id.text2);
TextView usernameTime = (TextView) convertView.findViewById((android.R.id.text1));
seeTexts.setText(messages.get(position).getMessage());
String messageInfo = messages.get(position).getUsername() + " - " + messages.get(position).getSendTime();
usernameTime.setText(messageInfo);
usernameTime.setTextColor(Color.BLACK);
seeTexts.setTextColor(Color.BLACK);
seeTexts.setTextSize(16);
usernameTime.setTextSize(13);
return convertView;
}
});
答案 0 :(得分:1)
您在应用程序中使用自定义Listview。请尝试以下代码:
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position,
long arg3)
{
String value = (String)adapter.getItemAtPosition(position);
}
});