I am using the base adapter , i have list which contains list with the text view (means left side sent items and below to that ,right side received items, i want to click on the each position in the list to perform replying the messaging .
Please suggest me how do i perform the function on clicking the listitem
Below is the code ,which i am using
class MessageAdapter extends 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" );
}
}
}
Below is the XML code which i am using
<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 >
Regards
Amrinder Singh
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…