Reputation: 528
This is my list with check box and 3 textviews.
Here is my adapter class for listview:
package android.virtus;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
public class Adapter extends BaseAdapter{
private Context context;
LayoutInflater inflater;
CheckBox box;
String textView1[], textView2[], textView3[];
public Adapter(Context c, CheckBox cb, String textView1[], String textView2[], String textView3[]) {
this.context=c;
this.box=cb;
this.textView1=textView1;
this.textView2=textView2;
this.textView3=textView3;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return textView1.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
View view=arg1;
view=LayoutInflater.from(context).inflate(R.layout.list, null);
view.setClickable(true);
view.setFocusable(false);
TextView tv1=(TextView)view.findViewById(R.id.tV1);
TextView tv2=(TextView)view.findViewById(R.id.tV2);
TextView tv3=(TextView)view.findViewById(R.id.tV3);
tv1.setText(textView1[arg0]);
tv2.setText(textView2[arg0]);
tv3.setText(textView3[arg0]);
return view;
}
}
This is my adapter which iam adding to listview in my activity.
here i want to navigate to another screen when an item of list is clicked. When i add onItemClick listener to list, But listview is not getting clicked.
Any help please.
My list.xml:
<?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="match_parent"
android:background="#EBEAE8"
>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/checkBox1">
<TextView
android:id="@+id/tV1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"
android:maxLines="1"
android:textSize="14sp"
android:textColor="#5e5d5c"/>
<TextView
android:id="@+id/tV2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"
android:textStyle="bold"
android:maxLines="2"
android:textSize="14sp"
android:textColor="#000000"
/>
</LinearLayout>
<TextView
android:id="@+id/tV3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"
android:layout_marginRight="10dp"
android:textSize="14sp"
android:textColor="#5e5d5c"
android:layout_alignParentRight="true"
android:layout_gravity="center"/>
Activity Class:
public class ReceivedRequests extends Activity
{
String URL="http://192.168.0.101/VirtusMobile/VirtusApi/UserRequest/GetMyRequests/hanan/false/true/false/false";
String Response;
Button back, btnSentRequest, btnNewRequest;
ListView listView;
CheckBox box;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.received_requests);
back=(Button)findViewById(R.id.back);
btnSentRequest=(Button)findViewById(R.id.btnSentRequest);
btnNewRequest=(Button)findViewById(R.id.btnNewRequest);
ReceiveTask task=new ReceiveTask();
task.execute();
listView=(ListView)findViewById(R.id.listView1);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent intent=new Intent(ReceivedRequests.this,RequestDetails.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.received_requests, menu);
return true;
}
}
EDIT:
Nothing is working in my case.
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
view.setClickable(true);
view.setFocusable(false);
android:focusable="true" attribute in ListView of my xml
or itemClickListener of ListView is also not working.
Any solution please?
Upvotes: 2
Views: 2416
Reputation: 554
add android:clickable="false"
in your checkbox. It prevents clicking.
Upvotes: 0
Reputation: 446
Update checkbox in your layout :
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentRight="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_centerVertical="true"/>
Upvotes: 7
Reputation: 1503
OK let me tell you that if there is any kind of UI items the that takes the view on it your listview onitemclicklistner
will not work example:checkbox,ImageButton,Button
these item takes View on it
and what view i am mean by its focus
so just set the check box android:focusable="false"
to false then it will work
Upvotes: 0
Reputation: 5068
add android:focusable="false"
in your checkbox. so list view item will get focus instead of checkbox.
Upvotes: 2