我正在使用基本适配器,我有一个列表,其中包含带有文本视图的列表(表示左侧发送的项目,下面是右侧接收的项目,我想单击列表中的每个位置以执行回复消息。
请建议我如何执行单击列表项的功能
下面是我正在使用的代码
类 MessageAdapter 扩展 BaseAdapter {
ViewHolder viewHolder;
LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
public int getCount() {
// TODO Auto-generated method stub
return Constant_Variables.Sms_Status_list.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.messagelist_row, null);
viewHolder=new ViewHolder();
viewHolder.sms_from_row=(TextView)convertView.findViewById(R.id.sms_from_txtview);
viewHolder.sms_to_row=(TextView)convertView.findViewById(R.id.sms_sendto_txtview);
}
else
{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.sms_from_row.setVisibility(View.VISIBLE);
viewHolder.sms_to_row.setVisibility(View.VISIBLE);
if(Constant_Variables.Sms_Status_list.get(position).equalsIgnoreCase(Twilioresponse_Utils.sms_sent))
{
viewHolder.sms_from_row.setVisibility(View.GONE);
viewHolder.sms_to_row.setText("Sent: "+Constant_Variables.Sms_from_list.get(position));
}
else if(Constant_Variables.Sms_Status_list.get(position).equalsIgnoreCase(Twilioresponse_Utils.sms_received))
{
viewHolder.sms_to_row.setVisibility(View.GONE);
viewHolder.sms_from_row.setText("Received: "+Constant_Variables.Sms_to_list.get(position));
}
else
{
viewHolder.sms_from_row.setText("Message in queued.");
viewHolder.sms_to_row.setVisibility(View.VISIBLE);
}
convertView.setTag(viewHolder);
return convertView;
}
protected void onListItemClick(ListView l, View v, final int position, long id) {
if(l.callOnClick()== true)
{
Log.i("the Item clicked is at position : ", ""+ position);
}
else
{
Log.i("the Item not clicked is at position : ","the Item not clicked is at position" );
}
}
}
下面是我正在使用的 XML 代码
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/sms_from_txtview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_alignParentRight="true"
android:background="@drawable/blue"
android:layout_alignParentTop="true"
android:text="From" />
<TextView
android:id="@+id/sms_sendto_txtview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:background="@drawable/red"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="To" />
</RelativeLayout >
问候阿姆林德·辛格