setOnItemClickListener not called in onCreatView method? - android

I am developing first android apps and I have a fragment class which extends SherlockListFragment. When I set setOnItemClickListener in onCreateView and implement onItemClick I'm getting no response when I click on a row(list). list display properly in my apps. I want when user click on row form listview my another activity will call. I goggled lot but not got proper answer.
I can't understand where is the problem. Can anyone tell me what am I doing wrong in following code?
following is the my code
public class ResidentialFragActivity extends SherlockListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle saved) {
View view = inflater.inflate(R.layout.project_list,container, false);
resListviewId = (ListView)view.findViewById(android.R.id.list);
linearProgress = (LinearLayout)view.findViewById(R.id.linlaHeaderProgress);
projectList = new ArrayList<HashMap<String,String>>();
new LoadProjects().execute();
resListviewId.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
Intent href = new Intent(getSherlockActivity(), ProjectDetailActivity.class);
// send project id to project detail activity to get list of Phases under that project
String proj_id = ((TextView) view.findViewById(R.id.projectId)).getText().toString();
href.putExtra("proj_id", proj_id);
getSherlockActivity().startActivity(href);
}
});
return view;
}
//inner class for network operation
private class LoadProjects extends AsyncTask<String, String, String> {
protected void onPreExecute() {
linearProgress.setVisibility(View.VISIBLE);
}
#Override
protected String doInBackground(String... params) {
//call webservice
}
#Override
protected void onPostExecute(String result) {
linearProgress.setVisibility(View.GONE);
ListAdapter projAdapter = new SimpleAdapter(getSherlockActivity(),
projectList, R.layout.project_list_item,
new String[] {PROJ_ID,PROJ_NAME,EDIT_RIGHTS}, new int[]
{R.id.projectId,R.id.projectName,R.id.projectSubName});
//updating the UI
setListAdapter(projAdapter);
}
}
}
following is the layout for listview
<?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="fill_parent"
android:layout_marginTop="10dp"
android:background="#color/White"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:divider="#drawable/divider"
android:focusableInTouchMode="true"
android:smoothScrollbar="true"
android:dividerHeight="1.5dp"
android:scrollbarThumbVertical="#drawable/divider"
android:drawSelectorOnTop="false"
android:listSelector="#drawable/list_selector">
</ListView>
</LinearLayout>
Thanks in advance..

You should override onListItemClick instead of instead of resListviewId.setOnItemClickListener .. as you are setting the adapter to the default one in setListAdapter(projAdapter);
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
Intent href = new Intent(getSherlockActivity(), ProjectDetailActivity.class);
// send project id to project detail activity to get list of Phases under that project
String proj_id = ((TextView) view.findViewById(R.id.projectId)).getText().toString();
href.putExtra("proj_id", proj_id);
startActivity(href);
}

Related

ListView OnClickListener is not working within Fragment

I'm trying to put a listener to my listview, which is inside my fragment. I've tried a few ways to do it, but still not working. I cannot make the other view focusable="false" because there is an EditText above the listview. Everytime I click the item, it calls the getView in the JSONAdapter that I created. Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<EditText
android:id="#+id/searchquery"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:hint="Search"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/list">
</ListView>
</LinearLayout>
Here is my Fragment :
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
mJSONAdapter = new JSONAdapter(getActivity(), inflater);
View v = inflater.inflate(R.layout.header, container, false);
return v;
}
#Override
public void onViewCreated(View view,Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListView lv = (ListView) getView().findViewById(android.R.id.list);
// Set the ListView to use the ArrayAdapter
lv.setAdapter(mJSONAdapter);//isi datany pk json adapter
lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(),Integer.toString(position),Toast.LENGTH_SHORT).show();
JSONObject jsonObject = (JSONObject) mJSONAdapter.getItem(position);//ambil item yg diclick
String raceid = jsonObject.optString("id","");//ambil cover id yg diklik, argumen kedua itu klo null defaultny apa
// create an Intent to take you over to a new DetailActivity
Intent detailIntent = new Intent(getActivity(), DetailActivity.class);
// pack away the data about the cover
// into your Intent before you head out
detailIntent.putExtra("raceid", raceid);
// start the next Activity using your prepared Intent
startActivity(detailIntent);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
new RetrieveFeedTask().execute();
}
You can try this code.
lv.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> adapter, View v, int position,
long arg3)
{
// do your work
}
});
It appears that I choose the wrong method. It should be OnItemClickListener(), instead I choose OnItemSelectedListener()

Populate ListView with ArrayList item on button click

I have an arraylist List<Cars> myCars = new ArrayList<Cars>(); My MainActivity layout has a listview and a button. There is one more layout
("each_car.xml") and its content is as below:-
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv_carName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/tv_carMaker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
My Cars class has two fields,"name" and "manufacturer".
public class Cars{
String name;
String manufacturer;
}
I am populating this list(myCars) through an async-task. After the task is complete i.e. inside onPostExecute(), I am calling a method in my MainActivity
which will populate a listview with the items in the list. Below is the method :-
public void populateListView(List<Cars> data){
ArrayAdapter<Cars> carAdapter = new CarAdapter(MainActivity.this, data);
ListView dataList = (ListView) findViewById(R.id.car_listView);
dataList.setAdapter(carAdapter);
}
Below is my CarAdapter class :-
public class CarAdapter extends ArrayAdapter<Cars>{
private LayoutInflater inflater;
List<Cars> dummyData = new ArrayList<Cars>();
MainActivity host;
public CarAdapter(MainActivity host, List<Cars> data)
{
super(host,R.layout.each_car,data);
inflater = host.getWindow().getLayoutInflater();
dummyData = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View itemView = convertView;
if(itemView == null)
{
itemView = inflater.inflate(R.layout.each_car,parent,false);
}
Cars currentData = dummyData.get(position);
Log.d("Testing Position","Position :- "+position);
TextView carName = (TextView) itemView.findViewById(R.id.tv_carName);
carName.setText(currentData.getName());
TextView carMaker = (TextView) itemView.findViewById(R.id.tv_carMaker);
carMaker.setText(currentData.getManufacturer());
return itemView;
}
}
This is filling out the listview with the entire List (myCars) at once.
Problem :- I want to populate the listView with one item at a time when I click the button.I am not sure how should I modify my code.
Check this link for custom adapterenter link description here. Once the list is populated pass the list into constructor of adapter and don't forget to call notifydatasetchanged. It will update the listview whenever an new item is added or removed from a listview.
This may help you ...
public class car extends AsyncTask<Void, Void, ArrayList<Cars> {
#Override
protected ArrayList<Cars> doInBackground(Void... params) {
... add your list here...
return myCars ;
}
#Override
protected void onPostExecute(ArrayList<Cars> result) {
super.onPostExecute(result);
//as per your requirement
adapter_car = new SimpleAdapter(ExchangeRateActivity.this, result,
R.layout.row, from, to);
list_view.setAdapter(adapter_car);
}
Here is a sample and easy way first you want to give the elements of 0 index element then on the next click you first clear the listview and then call your Adapter class with 2 element and repeat the same thing with some counter that takes the number of click and call you Adapter class with the limit of that Array list May be this Strategy help you..
Here are a couple of tutorials. You need to do some research and follow tutorials if you do not know what to do. link one, link two and link three
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</RelativeLayout>
adapter class
public class myListAdapter extends BaseAdapter{
List<String> item_list = new ArrayList<String>();
public myListAdapter(){
}
void add(String item_text){
item_list.add(item_text);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return item_list.size();
}
#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(int position, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.list_item, null);
TextView tvText = (TextView)view.findViewById(R.id.list_text);
tvText.setText(item_list.get(position));
return null;
}
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/list_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Implementation in onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListAdapter adapter = new myListAdapter();
ListView list = (ListView) findViewById(R.id.list);
adapter.add("Some value");
list.setAdapter(adapter);
}

Android list view shows blank elements

In my App i download a list of strings from the web
then i'm using AsyncTask to update the listview on my activity.
at prePostExecute im creating the array adapter(private member)
at doInBackground i download the list and return it
at onPostExecute i set the returned list to the adapter and then connects the listview and the adapter
in my activity i see just 1 blank element(instead of 2 elements) , when i click it i can see the Text but when im not its blank.
also , when my adapter is not android.R.layout.simple_list_1 but android.R.layout.acitiviy_list_item (and 2 other templates) i can see 2 elements with visible text but the text is small and gray
code:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dip" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#4CB8FB"
android:gravity="center"
android:text="Search"
android:textColor="#FAFAFA"
android:textSize="40sp" />
</TableRow>
<EditText
android:id="#+id/searchInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_btn_search" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fastScrollEnabled="true"
android:scrollingCache="true" >
</ListView>
</LinearLayout>
code Behind
public class ProductPickerActivity extends Activity {
private ListView listView;
private EditText inputSearch;
private ArrayAdapter<String> adapter;
private final Integer PRODUCT_REQUEST_ID = 5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product_listview);
inputSearch = (EditText) findViewById(R.id.searchInput);
inputSearch.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
ProductPickerActivity.this.adapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void afterTextChanged(Editable arg0) {
}
});
new InitializeUi().execute(this);
setupUI(findViewById(R.id.parent));
}
private class InitializeUi extends AsyncTask<Object, Void, List<IProduct>> {
#Override
protected void onPreExecute() {
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list);
// Define a new Adapter
// First parameter - Context
// Second parameter - Layout for the row
// Third parameter - ID of the TextView to which the data is written
// Forth - the Array of data
adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.activity_list_item, new ArrayList<String>());
// ListView Item Click Listener
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);
Intent intent = new Intent(getApplicationContext(), ProductViewActivity.class);
intent.putExtra("ProductName", itemValue);
startActivityForResult(intent, PRODUCT_REQUEST_ID);
}
});
}
#Override
protected List<IProduct> doInBackground(Object... params) {
// Defined Array values to show in ListView
IProductManager manager = new ProductManager(getApplicationContext());
// download from web
List<IProduct> lst = manager.GetProductList();
return lst;
}
#Override
protected void onPostExecute(List<IProduct> lst) {
String[] values = new String[lst.size()];
Integer i = 0;
for (IProduct p : lst) {
values[i] = p.getName();
i = i + 1;
Log.d("ProductPickerActivity", "Got Values : " + p.getName());
adapter.add(p.getName());
adapter.notifyDataSetChanged();
}
// Assign adapter to ListView
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
listView.refreshDrawableState();
}
}
}
apply the edit code below to onPostExecute hope its work
// Assign adapter to ListView
listView.setAdapter(adapter);
//then add values to adatper
String [] values = new String[lst.size()];
int i =0; //<<-- change to int
for(IProduct p : lst)
{
values[i] = p.getName();
i++;//<-- add +1
Log.d("ProductPickerActivity","Got Values : "+p.getName());
adapter.add(p.getName());
}
//finaly notify adapter data changed
adapter.notifyDataSetChanged();

ListActivity Android

Does somebody know why ListActivity won't work and when I change it to Activity base class, with slight changes it works, but onClick() method still doesn't. I'm trying only to put some strings into the list... Here's the code:
public class TestDataBaseActivity extends Activity implements OnClickListener {
private CommentsDataSource datasource;
ListView m_list;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
datasource = new CommentsDataSource(this);
datasource.open();
List<Comment> values = datasource.getAllComments();
m_list = (ListView) findViewById(R.id.listView1);
// Use the SimpleCursorAdapter to show the
// elements in a ListView
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
android.R.layout.simple_list_item_1, values);
m_list.setAdapter(adapter);
Button add = (Button)findViewById(R.id.button_add);
Button delete = (Button)findViewById(R.id.button_delete);
add.setOnClickListener(this);
delete.setOnClickListener(this);
}
// Will be called via the onClick attribute
// of the buttons in main.xml
#Override
public void onClick(View view) {
#SuppressWarnings("unchecked")
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) m_list.getAdapter();
Comment comment = null;
switch (view.getId()) {
case R.id.button_add:
String[] comments = new String[] {
"Cool", "Very nice", "Hate it"
};
int nextInt = new Random().nextInt(3);
// Save the new comment to the database
comment = datasource.createComment(comments[nextInt]);
adapter.add(comment);
break;
case R.id.button_delete:
if (m_list.getAdapter().getCount() > 0) {
comment = (Comment) m_list.getAdapter().getItem(0);
datasource.deleteComment(comment);
adapter.remove(comment);
}
break;
}
adapter.notifyDataSetChanged();
}
#Override
protected void onResume() {
datasource.open();
super.onResume();
}
#Override
protected void onPause() {
datasource.close();
super.onPause();
}
}
Here is XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TestDataBaseActivity" >
<Button
android:id="#+id/button_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_new" />
<Button
android:id="#+id/button_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/button_add"
android:text="#string/delete_first" />
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/button_add"
android:padding="15dp" >
</ListView>
</RelativeLayout>
I edited now to extend Activity, now "only" onClick() dont work...
Thanks in advance!
For a ListActivity, you should override onListItemClick() instead:
#Override
protected void onListItemClick(ListView lv, View v, int position, long id){
}
Since you are extending ListActivity you need to have an Listview with android:id="#android:id/list".
if you want to use #+id/lst_id then dont extend ListActivity, just extended Activity.
And whenever you are using Listview you need to implement OnItemClickListener not OnClickListener.
and override the default OnItemClick method
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
you should implement OnClickListener
public class TestDatabaseActivity extends ListActivity implements
OnClickListener{
try following code a simple list activity
public class MainActivity extends ListActivity implements OnItemClickListener {
ListView listView;
static final String[] SPORTS = {"Shuttle Badminton", "Tennis", "FootBall",
"Basket Ball","Table Tennis", "Chess","Hockey"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView = getListView();
//setting adapter
listView.setAdapter(new ArrayAdapter<String>(getApplicationContext(),R.layout.list_item,SPORTS));
listView.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
TextView tv = (TextView)view.findViewById(R.id.text1);
Toast.makeText(getApplicationContext(),"Position is: "+position,Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),"Text is: "+tv.getText().toString(),Toast.LENGTH_SHORT).show();
}
}
here list_item is an xml having following code
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#android:color/black"
android:padding="10dp" />
Use this code for list activity and modify row xml according to your needs.
hope this helps..
This is what's troubling you:
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) m_list.getAdapter();
Build a global object for your adapter instead. ( Declare it before onCreate() )

Android - setOnItemClickListener event of ListView not working in Fragment

Good morning,
I have a problem with the setOnItemClickListener event of a ListView inside a Fragment which is never fired.
Here is the code of the item in listView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dip" >
<ImageView
android:id="#+id/url_foto"
android:layout_width="100dip"
android:layout_height="100dip"
android:src="#drawable/stub"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/url_foto"
android:orientation="vertical"
android:paddingLeft="10sp" >
<TextView
android:id="#+id/nome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" />
<TextView
android:id="#+id/cognome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" />
Here is the xml code of the list (that also includes a edittext with some listeners):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/cerca_il_prof_edit_search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="search" />
<ListView
android:id="#+id/cerca_il_prof_list_result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="true"
android:focusable="true" />
and finally the fragment that contains the event which is not fired:
public class CercaIlProfFragment extends Fragment {
private DbAdapter dbHelper;
private Cursor cursor;
private Context ctx;
List<Professore> listProf;
private static final String TAG = "CercaIlProf - ";
private EditText string_search;
private ListView listViewProf;
int textlength = 0;
/**
* The fragment argument representing the section number for this fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.cerca_il_prof, container, false);
ctx = getActivity();
listProf = new ArrayList<Professore>();
string_search = (EditText) rootView.findViewById(R.id.cerca_il_prof_edit_search);
Date currDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(currDate);
calendar.add(Calendar.MONTH, 1);
// get all prof
getAllProf();
listViewProf = (ListView) rootView.findViewById(R.id.cerca_il_prof_list_result);
ProfessoreListAdapterWithCache professoreListAdapterWithCache = new ProfessoreListAdapterWithCache(ctx,
R.layout.cerca_il_prof_list_result_item, listProf, this.getActivity());
listViewProf.setAdapter(professoreListAdapterWithCache);
listViewProf.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "Click ListItem Number " + position, Toast.LENGTH_LONG).show();
}
});
listViewProf.setEnabled(true);
string_search.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Toast.makeText(getActivity(), "Click ListItem Number ", Toast.LENGTH_LONG).show();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//do stuff
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//do stuff
});
return rootView;
}
Can someone help me please??
Thanks in advance.
Regards.
Giuseppe
To expand upon #Ashwin's answer, note that the ListView blocks clicks of an item that contains at least one focusable
descendant but it doesn’t make the content focus-reachable calling
setItemsCanFocus(true). One workaround is by disabling focusability of descendants, using
android:descendantFocusability="blocksDescendants"
in the layout defining your list item, although you can just disable children that can take focus as he mentioned earlier. (First learned of this myself from http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/, but a few other SO posts also point this out.)
Just put android:focusable="false" android:clickable="false" in layout. For all textviews,buttons etc.
Works Fine.
Declare your listview and itemclick listener inside onViewCreated Like,
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final ListView listViewProf=(ListView)getActivity().findViewById(R.id.cerca_il_prof_list_result);
listViewProf.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
you will try this it will help you
lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
#Override
public void onItemClick(android.widget.AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
I found the solution. If you change the list item's (layout which you are setting in the listview adapter)layout child views to
android:clickable="false"
and
android:focusable="false"
it works.

Categories

Resources