Hi in my app I want to do some functionality on click of item in a list.
Here is the xml for the list item.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#FFFFFF"
android:layout_marginTop="20dp"
android:focusableInTouchMode="true" android:focusable="true">
<TableLayout android:layout_width="fill_parent" android:layout_marginTop="10dp"
android:layout_height="wrap_content" android:id="#+checklistitem/itemrow">
<TableRow android:id="#+checklistitem/tr">
<TextView android:id="#+checklistitem/texthead"
android:textStyle="bold"
android:visibility="gone" android:layout_marginLeft="10dp"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:paddingRight="0dp" android:maxLines="2" android:textSize="16dp"
android:text="Towel Rack: 2 hand towels,2 wash clothes"
android:background="#000000" android:textColor="#ffffff"
android:layout_centerVertical="true" />
<TextView android:id="#+checklistitem/textSeparator"
android:visibility="gone" android:layout_marginLeft="10dp"
android:layout_width="240dp" android:layout_height="fill_parent"
android:paddingRight="0dp" android:maxLines="2" android:textSize="16dp"
android:text=""
android:background="#000000" android:textColor="#ffffff"
android:layout_centerVertical="true" />
<TextView android:layout_marginLeft="5dp"
android:id="#+checklistitem/inspectionvalue" android:visibility="visible"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#006699" android:text="01"
android:layout_alignParentRight="true" android:layout_marginRight="8dp"
android:layout_centerVertical="true" />
</TableRow>
</TableLayout>
</RelativeLayout>
and here is the code where I used adapter for my list
checklistview.setOnItemClickListener(this);
CheckListAdapterForAtt checkAdapter = new CheckListAdapterForAtt(this.getApplicationContext(), checkListRowDataArr, R.layout.checklist_row);
But some how Item click listner does not working for me???
Add the following in the XML row layout where you want to click
android:clickable="false"
android:focusable="false"
Onclick listener Like following
mList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
}
});
try like this:
listView.setOnItemClickListener(new OnItemClickListener() {
private void OnItemSelected() {
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if(arg2 == 0)
{
}
if(arg2 == 1)
{
}
Related
I have a custom ListView item. setOnClickListener is not working. I've been searching for the solution for hours, but couldn't find anything. I think the problem is not 'set focusable false' things, because I've already done it. Please, help me.
payments_list_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp"
android:paddingLeft="10dp">
<ImageView
android:layout_width="46dp"
android:layout_height="35.3dp"
android:textColor="#000000"
android:id="#+id/payment_item_name2"
android:layout_gravity="center_horizontal|start"
android:src="#drawable/payments_internet"
android:textSize="20sp"
android:text="Test"
android:textStyle="bold"
android:capitalize="words" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8c8c8c"
android:id="#+id/payment_item_name"
android:layout_gravity="center_horizontal|center"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:text="Test"
android:textStyle="bold"
android:capitalize="words" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp"
android:layout_marginTop="12dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="15.3dp"
android:layout_height="20.1dp"
android:src="#drawable/arrow_right_red"
android:layout_gravity="center_vertical|right"
android:id="#+id/backButton"
android:textAllCaps = "true"
/>
</LinearLayout>
Here is my Activity onCreate:
ListView paymentsList = (ListView) findViewById(R.id.paymentsList);
paymentsList.setAdapter(testAdapter);
paymentsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.w("Clicked23", "CLicked23");
}
});
`
My Adapter:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View payments_list_item = inflater.inflate(R.layout.payments_list_item, parent, false);
String payment = getItem(position);
TextView payment_item_name = (TextView) payments_list_item.findViewById(R.id.payment_item_name);
payment_item_name.setText(payment.toUpperCase());
return payments_list_item;
}
//EDIT
Finally solved my problem
Thanks to #mustafasevgi`s answer:
I added
android:descendantFocusability="blocksDescendants" to my custom ListView item layout.
Can you add this code?
android:descendantFocusability="blocksDescendants"
payment_list_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp"
android:paddingLeft="10dp">
<ImageView
android:layout_width="46dp"
android:layout_height="35.3dp"
android:textColor="#000000"
android:id="#+id/payment_item_name2"
android:layout_gravity="center_horizontal|start"
android:src="#drawable/payments_internet"
android:textSize="20sp"
android:text="Test"
android:textStyle="bold"
android:capitalize="words" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8c8c8c"
android:id="#+id/payment_item_name"
android:layout_gravity="center_horizontal|center"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:text="Test"
android:textStyle="bold"
android:capitalize="words" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp"
android:layout_marginTop="12dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="15.3dp"
android:layout_height="20.1dp"
android:src="#drawable/arrow_right_red"
android:layout_gravity="center_vertical|right"
android:id="#+id/backButton"
android:textAllCaps = "true"
/>
</LinearLayout>
check the following code:
public class CustomListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
ListView paymentsList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_list);//your layout view
paymentsList = (ListView) findViewById(R.id.paymentsList);
paymentsList.setAdapter(testAdapter);
paymentsList.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
//your logic
Toast.makeText(this, "Listview Clicked", Toast.LENGTH_SHORT).show();
}
}
Try this:
paymentsList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.w("Clicked23", "CLicked23");
}
});
Remove this from your xml
android:focusable="false"
android:focusableInTouchMode="false"
how about modifying your payments_list_item to this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingTop="12dp">
<ImageView
android:id="#+id/payment_item_name2"
android:layout_width="46dp"
android:layout_height="35.3dp"
android:src="#drawable/payments_internet"/>
<TextView
android:id="#+id/payment_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Test"
android:textColor="#8c8c8c"
android:textSize="20sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/backButton"
android:layout_width="15.3dp"
android:layout_height="20.1dp"
android:layout_gravity="center_vertical|right"
android:src="#drawable/arrow_right_red"/>
</LinearLayout>
you have written very complex layout..
I have a fragment with a ListView and two buttons above this ListView. The two buttons call the following methods which reload the ListView with a different adapter for the data source. The problem is with the second one. When calling the showWhenWhere(), the onItemClick() is never fired.
private void showAtoZ() {
lineupAdapter = new LineupAdapter(parentView.getContext());
listView.setAdapter(lineupAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// ListView Clicked item index
System.out.println("A to Z tapped");
int itemPosition = position;
if(parentActivity != null) {
parentActivity.changeFragment(new BandFragment());
}
}
});
loadData();
}
private void showWhenWhere() {
whenWhereAdapter = new LineupWhenWhereAdapter(parentView.getContext());
listView.setAdapter(whenWhereAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// ListView Clicked item index
System.out.println("When/Where tapped");
int itemPosition = position;
if(parentActivity != null) {
parentActivity.changeFragment(new BandFragment());
}
}
});
loadData();
}
UPDATE - I determined it's caused by the XML for the whenWhereAdapter, which I'm pasting below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="150dp" android:id="#+id/lineupWhenWhereView">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bandImageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:scaleType="centerCrop"
android:background="#android:color/darker_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""
android:id="#+id/textView"
android:background="#drawable/list_row_bg" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Elijah & The Moon"
android:id="#+id/bandTitle"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="30dp"
android:textSize="23sp"
android:maxLines="2"
android:textColor="#android:color/white" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#android:color/black">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12:00 PM"
android:id="#+id/whenLabel"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="#android:color/holo_orange_light"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:id="#+id/divider"
android:layout_toRightOf="#+id/whenLabel"
android:layout_toEndOf="#+id/whenLabel"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="6dp"
android:layout_alignParentBottom="true"
android:textIsSelectable="true"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="West Stage"
android:id="#+id/whereLabel"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/divider"
android:layout_toEndOf="#+id/divider"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:textSize="12sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD TO SCHEDULE"
android:id="#+id/addButton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#android:color/transparent"
android:drawableLeft="#drawable/add_to_schedule"
android:drawablePadding="5dp"
android:textColor="#android:color/holo_orange_light"
android:layout_marginRight="10dp" />
</RelativeLayout>
</RelativeLayout>
Any idea why this would cause the OnItemClickListener to not work?
ListView only maintains one OnItemClickListener at time. When you set the second listener, only that listener will be called.
-------EDIT -------
After seeing your row layout, I think you should set
android:descendantFocusability="blocksDescendants"
on your very first RelativeLayout.
That happen because TextViews && Buttons inside layout are blocking click event.
I have a listview. And i need do click in each element inside listview. But the onItemClickListener don't work. I try put each textView with focusable="false" and put android:descendantFocusability="blocksDescendants" but nothing works and i don't know where is my error.
Here is my code
xml of each element inside listview
**xml_item_list**
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dip"
android:paddingBottom="8dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="#android:drawable/list_selector_background"
android:clickable="true"
android:longClickable="true"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/lDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:background="#drawable/et_style"
android:gravity="center"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:focusable="false" />
<TextView
android:id="#+id/lDescription"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:gravity="center"
android:background="#drawable/et_style"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:focusable="false"/>
<TextView
android:id="#+id/lMissValue"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:gravity="center_horizontal|center"
android:layout_gravity="center"
android:textColor="#DDCC2EFA"
android:textAppearance="?android:attr/textAppearanceMedium"
android:focusable="false"/>
</TableRow>
**main_xml_list**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_tile"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="50dp">
<ImageView
android:id="#+id/bankTransaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"/>
<TextView
android:id="#+id/contextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/et_style"
android:textSize="28dp"
android:layout_gravity="bottom" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
</ListView>
</LinearLayout>
Code inside onCreate() function of activity
onCreate()
listView = getListView();
listView.setClickable(true);
listView.setOnItemClickListener(
new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
Log.w(TransactionView.class.getName(), "Item click listener");
Toast.makeText(TransactionView.this, "Item clicado", Toast.LENGTH_LONG).show();
}
}
);
Anyone can help me?
Thanks for yout time.
try like this
lvlList = (ListView)findViewById(R.id.lvlList);
lvlList.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a, View v,int position, long id)
{
Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show();
}
});
First of all,check that you have added this line or not in your code.
public class MyActivity extends Activity implements OnItemClickListener
Then add this code in your onCreate() of activity ...
ListView listView = (ListView) findViewById(R.id.lisview);
listView.setOnItemClickListener(this);
#Override
public boolean onItemClick(AdapterView<?> parent, View v, int pos,long id)
{
System.out.println("~~~~~~Item Clicked");
return false;
}
change this ::
android:id="#+id/list"
Hope this helps :)
My Solution.....
public class TransactionView extends ListActivity implements **AdapterView.OnItemClickListener**{}
**onCreate()**{
adapter = new SimpleCursorAdapter(
this,
R.layout.transaction_item_view,
c,
new String[]{MySQLiteHelper.C_TRANSACTION_DUE, MySQLiteHelper.C_TRANSACTION_DESCRIPTION, MySQLiteHelper.C_TRANSACTION_VALUE, MySQLiteHelper.C_TRANSACTION_COVERVALUE, MySQLiteHelper.C_TRANSACTION_STATE, MySQLiteHelper.C_TRANSACTION_SOURCE},
new int[]{ R.id.lDate, R.id.lDescription, R.id.lMissValue},SimpleCursorAdapter.IGNORE_ITEM_VIEW_TYPE);
}
setListAdapter(adapter);
listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
Log.w(TransactionView.class.getName(), "Item click listener");
Toast.makeText(TransactionView.this, "Item clicado", Toast.LENGTH_LONG).show();
}
}
);
**item_list_row**
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dip"
android:paddingBottom="8dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="#android:drawable/list_selector_background"
>
<TextView
android:id="#+id/lDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:background="#drawable/et_style"
android:gravity="center"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/lDescription"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:gravity="center"
android:background="#drawable/et_style"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/lMissValue"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:gravity="center_horizontal|center"
android:layout_gravity="center"
android:textColor="#DDCC2EFA"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
**main_xml_list**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_tile"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
I have an activity with a ListView. ListView with custom views. I add OnItemClickLIstener to the ListView. and when i click on item, in result i see nothing.
Activity with ListView:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/silver_conv">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="40dp" android:layout_alignParentTop="true" android:id="#+id/topcontainer"
android:background="#color/black">
</FrameLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/chat_list" android:layout_below="#+id/topcontainer"
android:layout_above="#+id/last_action"
android:cacheColorHint="#00000000"
android:layout_marginRight="2dp" android:clickable="true"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="last action was at time" android:id="#+id/last_action"
android:longClickable="false"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="false" android:layout_above="#+id/action_container"
android:layout_marginBottom="5dp" android:layout_alignParentLeft="false" android:layout_marginLeft="5dp"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="43dp" android:layout_alignParentBottom="true" android:id="#+id/action_container"
android:background="#drawable/conv_botom_action_gradient">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="#string/send"
android:id="#+id/send_message_btn" android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#drawable/blue_button_selector" android:textColor="#color/white"
android:layout_marginLeft="3dp" android:layout_marginTop="3dp"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/add_attach_btn"
android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"
android:background="#drawable/add_attach_button_selector"
android:layout_marginRight="2dp" android:layout_marginBottom="3dp" android:layout_marginTop="3dp"/>
<EditText android:layout_width="40dp" android:layout_height="wrap_content" android:id="#+id/message_et"
android:layout_toRightOf="#+id/add_attach_btn" android:layout_toLeftOf="#+id/send_message_btn"
android:singleLine="true" android:layout_alignParentBottom="true" android:hint="Type message here"
android:background="#drawable/message_input" android:layout_marginBottom="3dp"
android:gravity="center_vertical" android:layout_marginTop="3dp"/>
</RelativeLayout>
View item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center_vertical|left" android:focusable="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="#drawable/incoming_message"
android:id="#+id/container" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
android:focusable="false">
<FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
android:focusableInTouchMode="true" android:id="#+id/attach_container" android:focusable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="saa"
android:id="#+id/message_text" android:textSize="17sp" android:textColor="#color/black"
android:focusable="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/date" android:textColor="#color/black" android:singleLine="true" android:lines="1"
android:maxLines="1" android:ellipsize="none" android:layout_marginLeft="5dp" android:focusable="false"/>
And finally clickListener:
private AdapterView.OnItemClickListener clickLister = new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
try {
LinearLayout container = (LinearLayout)view.findViewById(R.id.container);
TextView message = (TextView)container.findViewById(R.id.message_text);
message.setTextColor(mContext.getResources().getColor(R.color.white));
Log.e("My item is", "" + pos);
}catch (Exception e){
e.printStackTrace();
}
}
};
And here is Initialization of ListView:
mConvListView = (ListView)findViewById(R.id.chat_list);
mConvListView.setDivider(null);
mConvListView.setDividerHeight(0);
mConvListView.setItemsCanFocus(false);
mConvListView.setOnItemClickListener(clickLister);
mConvListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
mConvListView.setStackFromBottom(true);
P.s. Sorry for a lot code. But I can't find any suggestion a second day.
By setting focusable objects in your row layout, you are preventing the ListView from getting the touch event.
This FrameLayout is consuming the touch event:
<FrameLayout
android:id="#+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:focusable="false"/>
Remove the focusable settings so it looks like this:
<FrameLayout
android:id="#+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
(You really should organize your XML so that is is readable, in Eclipse use Ctrl+Shift+F.)
Make Focus for all components as follows :
android:focusable="false"
android:focusableInTouchMode="false"
I guess you are not getting the item the right way. Try this:
int position = (int) adapterView.getSelectedItemId();
Log.i("Position:", Integer.toString(position));
Edit
Try this piece of code.
ListView lv = (ListView)findViewById(R.id.chat_list);
lv.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
int position = (int) parent.getSelectedItemId();
Log.i("Position:", Integer.toString(position));
}
});
I got ListActivity, each item has 2 textviews image and CheckedTextView. I am trying to implement simple multichoiselist...
I have two problems:
1.
#Override
protected void onListItemClick(android.widget.ListView l, View v,
int position, long id)
{
...
}
doesnt respond at all I have tried it with the debugger and when I press on any list item it doesnt stop there. and I have tried all kind of things (like focusable:false)
two:.
I cant toggle the CheckedTextView anyhow.
here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100sp"
android:focusable="false" android:focusableInTouchMode="false">
android:padding="6dip">
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="#drawable/icon"
android:id="#drawable/icon" android:layout_marginLeft="6dip"
android:focusable="false" android:focusableInTouchMode="false">
</ImageView>
<LinearLayout android:id="#+id/LinearLayout01"
android:orientation="vertical" android:layout_width="1sp"
android:layout_height="fill_parent" android:layout_weight="1"
android:focusable="false" android:focusableInTouchMode="false">
<TextView android:id="#+id/toptext" android:layout_weight="1"
android:gravity="center_vertical" android:text="OrderNum"
android:singleLine="true" android:layout_height="0dp"
android:layout_width="wrap_content" android:focusable="false"
android:focusableInTouchMode="false">
</TextView>
<TextView android:id="#+id/bottomtext" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:focusable="false"
android:focusableInTouchMode="false" android:text="TweetMsg">
</TextView>
<TextView android:id="#+id/twittLocation"
android:layout_weight="1" android:text="location" android:singleLine="true"
android:layout_width="fill_parent" android:layout_height="0dip"
android:focusable="false" android:focusableInTouchMode="false">
</TextView>
<TextView android:layout_weight="1" android:id="#+id/twittLocationlink"
android:text="locationlink" android:gravity="fill_horizontal"
android:layout_width="fill_parent" android:layout_height="0dip"
android:focusable="false" android:focusableInTouchMode="false">
</TextView>
</LinearLayout>
<CheckedTextView android:id="#android:id/text1" android:text="Delete"
android:layout_width="wrap_content" android:layout_marginRight="2dp"
android:layout_height="fill_parent"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:focusable="false"></CheckedTextView>
</LinearLayout>
any idea what's the problem?
thanks.
In your ListView set android:descendantFocusability="beforeDescendants". This might help.
Try this code:
public class Sample extends ListFragment implements OnItemClickListener{
ListView list;
list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
}
});
}
Sample code