simpleAdapter thumbnail and text and onItemClick handler - android

In my app I need to show a list of thumbnail with their own relative title.
Here's my implementation.
String tempTarget;
List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
for(int i = 0; i<ARelements.size();i++){
Element ar = arIterator.next();
Map<String,Object> map = new HashMap<String,Object>(2);
tempTarget = ar.getAttributeValue("TARGET");
thumbnailBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(tempTarget), THUMBSIZE, THUMBSIZE);
map.put("thumbnail", thumbnailBitmap);
map.put("titolo", tempTarget);
data.add(map);
Log.i("list",thumbnailBitmap.toString());
}
arIterator= null;
SimpleAdapter simpleAdapter = new SimpleAdapter(this,data,R.layout.row,new String[] {"thumbnail","titolo"},new int[] {R.id.imageView, R.id.titoloTv});
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapter, final View componente, int pos, long id){
List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
res = (List<Map<String, Object>>) adapter.getItemAtPosition(pos); //classCastExeption
Log.i("list","assegamento a res eseguito");
titoloriga = (String) res.get(pos).get("titolo");
Log.i("list","assegamento a titoloriga eseguito");
Log.i("list", "Ho cliccato sull'elemento con titolo" + titoloriga+" " +Integer.valueOf(pos)+" "+Long.valueOf(id));
registerForContextMenu(componente);
componente.showContextMenu();
}
});
I have two problems:
1. The simple adapter show me only the title but not the thumbnail.
2. I don't know how to handle the onItemClick, i need to store the title. In this way I have the ClassCastExeption and the warning of unsafety cast.
Here' s the layout of the single row and of the listview.
<?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="50dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView"
android:layout_width="65dp"
android:layout_height="65dip"
/>
<TextView
android:id="#+id/titoloTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imageView"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
and
<?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" >
<Button
android:id="#+id/creaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Crea una nuova realtà aumentata" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Ar già create"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
Thank's

On Item click of ListView, you don't need to create a Hash map arraylist again you can get by which is stored in your ArrayList of hashmap.. So change
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapter, final View componente, int pos, long id){
String title = data.get(pos).get("titolo");
String thumbimage = data.get(pos).get("thumbnail");
registerForContextMenu(componente);
componente.showContextMenu();
}
});

Related

Android ListView items onClick with CursorAdapter only working after some clicks

This is the ListFragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_list, container, false);
listList = (ListView) root.findViewById(R.id.list_list);
mListAdapter = new ListCursorAdapter(getActivity(),null);
FloatingActionButton addFab = (FloatingActionButton) root.findViewById(R.id.fabAdd);
addFab.setFocusable(false);
addFab.setFocusableInTouchMode(false);
mDBAdapter = new DBAdapter(getContext());
mDBAdapter.open();
id = new ArrayList<Integer>();
nombres = new ArrayList<String>();
latitudes = new ArrayList<Double>();
longitudes = new ArrayList<Double>();
descripciones = new ArrayList<String>();
categorias = new ArrayList<Integer>();
listList.setAdapter(mListAdapter);
empty = (TextView) root.findViewById(R.id.tvEmpty);
Cursor listas = mDBAdapter.getListaListas();
if(listas==null || listas.getCount()<=0) empty.setVisibility(View.VISIBLE);
listList.setClickable(true);
AdapterView.OnItemClickListener myListViewClicked = new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
cur = mDBAdapter.getListaListas();
int id_lis;
String name_lis;
if (cur.moveToFirst()) {
for (int k=0;k<i;k++){
cur.moveToNext();
}
}
id_lis = cur.getInt(0);
name_lis = cur.getString(1);
Intent intent = new Intent(getContext(), MarkerListActivity.class);
intent.putExtra("numLista", id_lis);
Log.i("id_lista", ""+ id_lis);
intent.putExtra("nameLista", name_lis);
startActivity(intent);
}
};
listList.setOnItemClickListener( myListViewClicked );
listList.setLongClickable(true);
It has also a long click event that displays some options. At first, I put the Intent in there, but this is the common way to do it.
The adapter it's a normal CursorAdapter with only a textview in it.
These are the XML files:
list_item
<?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"
android:descendantFocusability="blocksDescendants"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/click"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="#+id/list_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:longClickable="true"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false"/>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="#B6B6B6"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
/>
</LinearLayout>
</LinearLayout>
And this is the fragment_list layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListFragment"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants">
<ListView
android:id="#+id/list_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/tvEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:hint="Ninguna lista para mostrar"
android:textSize="25sp"
android:textStyle="bold"
android:visibility="invisible"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabAdd"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="12dp"
android:tint="#android:color/white"
app:fabSize="normal"
app:srcCompat="#drawable/ic_action_add" />
</FrameLayout>
So, how can I do to get the onItemClick working with a simple click? It always takes four or more clicks to open the new Activity.
Thank you so much.
Your onItemClicked method does database operations on the UI thread. This is something you should avoid and it causes bad user experience. Wrap your code inside an AsyncTask and execute it like the following:
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("onItemClick", "clicked Item")
AsyncTask task = new AsyncTask<Void, Void, Void>() {
private int id_lis;
private String name_lis;
protected Long doInBackground(Void... voids) {
cur = mDBAdapter.getListaListas();
if (cur.moveToFirst()) {
for (int k=0;k<i;k++){
cur.moveToNext();
}
}
id_lis = cur.getInt(0);
name_lis = cur.getString(1);
}
protected void onPostExecute(Long result) {
Intent intent = new Intent(getContext(), MarkerListActivity.class);
intent.putExtra("numLista", id_lis);
Log.i("id_lista", ""+ id_lis);
intent.putExtra("nameLista", name_lis);
startActivity(intent);
}
}.execute();
}

Android listview hide button

I have a problem how to hide the button in specific row in my listview with SimpleAdapter. This is my sample code.
alert_noti_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
alert_pop_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:orientation="vertical"
>
<TextView
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="view1"
android:textSize="20dp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/confirm"
android:layout_toStartOf="#+id/confirm" />
<TextView
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10dp"
android:textStyle="bold"
android:visibility="visible"
android:layout_below="#+id/view1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/confirm"
android:layout_toStartOf="#+id/confirm" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/confirm"
android:layout_alignBottom="#+id/view2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/ic_confirm" />
</RelativeLayout>
Activity :
List<Map<String, String>> listData = new ArrayList<Map<String, String>>();
Map<String, Object> names = new HashMap<String, Object>();
names.put("First","head1");
names.put("Second", "txt1");
names.put("First","head2");
names.put("Second", "txt2");
names.put("First","head3");
names.put("Second", "txt3");
...
listData.add((HashMap) names);
ListView lv = (ListView) dialog_mail.findViewById(R.id.listView1);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(home.this,, android.R.layout.two_line_list_item, names);
SimpleAdapter adapter = new SimpleAdapter(home.this, listData,
R.layout.alert_pop_list,
new String[] {"First", "Second" },
new int[] {R.id.view1, R.id.view2});
lv.setAdapter(adapter);
how do i hide the button if the value is head2 and show to the rest of the list.
You need to custom a BaseAdapter instead of SimpleAdapter and write some code at getView() method。 just like:
public View getView(int p,View view,ViewGroup parent) {
if (view == null) {
view = LayoutInflate.xxxx;
}
Button btn = (Button) view.findViewById(R.id.btn);
DataModel d = list.get(p);
if (d.isHidden || d.data.equals("head2")) {
btn.setVisibility(View.GONE);
} else {
btn.setVisibility(View.visible);
}
return view;
}
so you need to create a DataModel to store some property.
public class DataModel {
public boolean isHidden;
public HashMap<String,String> dataMap;
//and so on.....
}

how to display Not Listview found item in android

public static void loadPopupData(Context context, final ListView listView) {
final DataBaseManager dbManager1 = new DataBaseManager(context);
final ArrayList<Notify> notifies = dbManager1.getNotificationList(15);
Notifcationadapter adapter = new Notifcationadapter(context, notifies);
listView.setAdapter(adapter);
listView.setEmptyView(emptyView);
}
This method is use to Print data In listview :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup"
android:layout_width="fill_parent"
android:layout_height="350dip" >
<RelativeLayout
android:id="#+id/rl_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:background="#00000000" >
<ImageView
android:id="#+id/image_tringle"
android:layout_width="40px"
android:layout_height="21px"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="50dp"
android:src="#drawable/notficationarrow_icon" />
</RelativeLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/textView1"
android:background="#anim/notifcationitembroder" >
</ListView>
<TextView android:id="#+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/listView1"
android:layout_alignBottom="#+id/listView1"
android:gravity="center"
android:visibility="invisible"
android:text="No items in list" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rl_top"
android:background="#drawable/bgnotifcationlayoutback"
android:gravity="center"
android:paddingBottom="20dp"
android:text="Notification"
android:textColor="#666666"
android:paddingTop="2dp"
android:textSize="20dip"
android:textStyle="bold" />
</RelativeLayout>
This is Xml File where am Printing Listview .
i want when there is no item in Listview then it should display Not found Listview am try to do But unable to display it please suggest me how to display Not found item if there is not item in list view .
You can use empty views for listview
Setting emptyview to Listview
Try this one. If this is not your solution in else add another view to display there is no any records to display
public String[] getSociety() {
int pos = 0;
MFDbBHelper mDbHelper = new MFDbBHelper(this);
List<Society> society = mDbHelper.getAllSociety();
String[] values = null;
if (society.size() > 0) {
values = new String[society.size()];
for (Society socty : society) {
values[pos] = socty.get_society_name();
// Writing Society to log
String log = "Id: " + socty.get_society_id() + " ,Name: "
+ socty.get_society_name();
Log.d("Insert: ", log);
pos++;
}
} else {
values = new String[0];
values[0] = "No records found!";
}
return values;
}
Add a text view which shows "No Results" in your popup's xml file and give it a id.
something like this
<TextView android:id="#+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/listView1"
android:layout_alignBottom="#+id/listView1"
android:gravity="center"
android:text="No items in list"
android:visibility="invisible"/>
And in code part set the textview as emptyview of your listview.
public static void loadPopupData(Context context, final ListView listView) {
final DataBaseManager dbManager1 = new DataBaseManager(context);
final ArrayList<Notify> notifies = dbManager1.getNotificationList(15);
Notifcationadapter adapter = new Notifcationadapter(context, notifies);
listView.setAdapter(adapter);
listView.setEmptyView(findViewById(R.id.emptyView));
}
Please add this in your xml
<TextView android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Results" />
and this code in your activity contains list
public static void loadPopupData(Context context, final ListView listView) {
final DataBaseManager dbManager1 = new DataBaseManager(context);
final ArrayList<Notify> notifies = dbManager1.getNotificationList(15);
Notifcationadapter adapter = new Notifcationadapter(context, notifies);
listView.setAdapter(adapter);
listView.setEmptyView(findViewById(android.R.id.empty));
}

ListView OnItemClickListener not Working

I create a statistics activity with listView . but onItemClick Not working I surffed internet but given solution not working for me.
try
{
int counter=0;
db = helper.getReadableDatabase();
c = db.query(DBHelper.Result, null, null, null, null, null, null);
c.moveToFirst();
do
{
counter++;
States state = new States(c.getString(2), c.getString(3), false);
stateList.add(state);
}while(c.moveToNext());
Log.d("counter", ""+counter);
/*adapter = new SimpleCursorAdapter(this, R.layout.row, c, new String [] {DBHelper.R_test,DBHelper.R_testNM}, new int []{R.id.rowTxt1,R.id.rowTxt2});
Lv.setAdapter(adapter);
Lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);*/
db.close();
}
catch(Exception e)
{
e.printStackTrace();
Log.d("Error", ""+e.getMessage());
}
// create an ArrayAdaptar from the String Array
dataAdapter = new MyCustomAdapter(this, R.layout.row, stateList);
//ListView listView = (ListView) findViewById(R.id.LvStatistics);
// Assign adapter to ListView
Lv.setAdapter(dataAdapter);
Lv.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
Log.d("click", "0");
}
});
row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Background"
android:orientation="vertical" >
<TextView
android:id="#+id/rowTxt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/ExamFontColor"
/>
<TextView
android:id="#+id/rowTxt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rowTxt1"
android:layout_marginLeft="20dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/FontBlack"
/>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:text="1" />
</RelativeLayout>
exam_statistics.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Background"
android:orientation="vertical" >
<TextView
android:id="#+id/statisticsHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#color/HeaderColor"
android:gravity="center"
android:text="#string/ButtonStatistics"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/FontWhite"
android:textSize="30sp" />
<ListView
android:id="#+id/LvStatistics"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/btnDelete"
android:background="#color/Background"
>
</ListView>
<Button
android:id="#+id/btnDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/statisticsHeader"
android:layout_marginBottom="10dp"
android:background="#drawable/button_green_effect"
android:text="#string/ButtonDelete"
android:textColor="#color/FontWhite"
android:textSize="27sp" />
</RelativeLayout>
I tried a Lot but not Working help me to solve this problem
write this in ur xml inside checkbox tag
android:focusable="false"
try after using this..
If your MyCustomAdapter implements OnItemClickListener so you have to use the following code :
MyCustomAdapter.setOnItemclikListener(dataAdapter);
As there is a checkBox in the row, ListView OnitemClickListener wont work. You can write OnItemClickLister in the row (Adapter) , to get the click event.
If you add args2 in log does it return the click position?
Log.d("click", "Row " + args.toString);

ListView Item not clickable

im trying to make an activity that searches a DB based on an input string and then returns the results in a list view. All this is working however, My listview items are not clickable. I have tried changing the focus and clickable attributes but nothing has worked so far.
Main XML (add_friend_layout.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" >
<LinearLayout android:id="#+id/AddFriendHeaderLayout"
android:layout_marginTop="3dip"
android:layout_height="45dip"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:gravity="center">
<EditText
android:id="#+id/et_SearchFriend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:ems="10"
android:inputType="text" />
<Button
android:id="#+id/bt_SearchFriend"
android:layout_width="wrap_content"
android:layout_height="40dip"
android:focusable="false"
android:icon="#android:drawable/ic_search_category_default"
android:text="Search" >
</Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="60dip"
android:layout_marginBottom="5dip"
android:layout_alignParentBottom="true"
android:layout_above="#+id/AddFriendHeaderLayout"
android:id="#+id/searchFriendFooterLayout">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</RelativeLayout>
ListView XML (single_listview_layout.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="wrap_content"
android:clickable="true" >
<TextView
android:id="#+id/tv_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20sp" >
</TextView>
</LinearLayout>
Main Java Function (SearchFriendActivity.java):
public class SearchFriendActivity extends ListActivity {
//Progress Dialog
private ProgressDialog pDialog;
private Button bt_searchFriend;
private EditText et_Search_String;
private ListView tv_listview;
String[] arrFriends;
String[] arrUserId;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
setContentView(R.layout.add_friend_layout);
bt_searchFriend= (Button) findViewById(R.id.bt_SearchFriend);
et_Search_String = (EditText) findViewById(R.id.et_SearchFriend);
tv_listview = (ListView) findViewById(R.id.tv_list);
String searchString="";
//searchString = String.valueOf(et_Search_String.getText());
Log.i ("log_search","value of searchString: " + searchString);
bt_searchFriend.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
try{
searchFriends aTask = new searchFriends();
aTask.execute(String.valueOf(et_Search_String.getText()));
String rResult = aTask.get();
// Convert aResult to array
arrFriends = convertJSONData(rResult);
arrUserId = convertJSONDataToUserArray(rResult);
setListAdapter(new ArrayAdapter<String>
(getBaseContext(),
R.layout.single_listview_layout,
R.id.tv_list,
arrFriends));
}catch(Exception e){
Log.e ("log_search_load",e.toString());
}
}
});
tv_listview = getListView();
//handler for List Item click
tv_listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
"Friend request sent for " +
((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
Log.i("log_search_listclick", "Listview clicked");
}
});
}catch(Exception e){
Log.e ("log_search_load2",e.toString());
}
}
Firstly, don't use focusable and clickable. When you use setOnclick or another they are auto creating.
Secondly, remove try cache blog then start application. Because when the problem created program will contining and you can't understand where is the problem.
===>Thirdly<====
you are used (tv_listview=...) second twice
tv_listview = (ListView) findViewById(R.id.tv_list);
tv_listview = getListView();
then you are trying tv_listview.setOnItemClickListener..... If second view is not first view seton not working on "R.id.tv_list".

Categories

Resources