How to make a ListActivity with custom List Item with nested clickable Button?

I edited my code to be compatible with yours I write your code with modification to achieve what you want... I call InitialActivity yo yhe ListActivity and populate the list from a string array (populate them is not your problem) so, maybe the other things will help you package com.franco. Test2; import java.util. ArrayList; import android.app.

ListActivity; import android.content. Context; import android.os. Bundle; import android.util.

Log; import android.view. LayoutInflater; import android.view. View; import android.view.View.

OnClickListener; import android.view. ViewGroup; import android.widget. AdapterView; import android.widget.AdapterView.

OnItemClickListener; import android.widget. ArrayAdapter; import android.widget. Button; import android.widget.

ListView; import android.widget. TextView; public class InitialActivity extends ListActivity { // private List friends; //lista de amigos private ArrayList usernames; //lista de usernames de amigos, para rellenar el listview private String usernames_array; private ActivityList listAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); // setContentView(R.layout. Main); usernames_array = getResources(). GetStringArray(R.array.

Usernames); actualizar(); } public void actualizar() { //friends = con. RetrieveFriends(settings. GetString("login","")); // friends = MyApplication.

GetDatabaseAdapter(). RetrieveAllFriends(); // usernames.clear(); // for (int i=0;i.

I edited my code to be compatible with yours I write your code with modification to achieve what you want... I call InitialActivity yo yhe ListActivity and populate the list from a string array (populate them is not your problem) so, maybe the other things will help you... package com.franco. Test2; import java.util. ArrayList; import android.app.

ListActivity; import android.content. Context; import android.os. Bundle; import android.util.

Log; import android.view. LayoutInflater; import android.view. View; import android.view.View.

OnClickListener; import android.view. ViewGroup; import android.widget. AdapterView; import android.widget.AdapterView.

OnItemClickListener; import android.widget. ArrayAdapter; import android.widget. Button; import android.widget.

ListView; import android.widget. TextView; public class InitialActivity extends ListActivity { // private List friends; //lista de amigos private ArrayList usernames; //lista de usernames de amigos, para rellenar el listview private String usernames_array; private ActivityList listAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); // setContentView(R.layout. Main); usernames_array = getResources(). GetStringArray(R.array.

Usernames); actualizar(); } public void actualizar() { //friends = con. RetrieveFriends(settings. GetString("login","")); // friends = MyApplication.

GetDatabaseAdapter(). RetrieveAllFriends(); // usernames.clear(); // for (int i=0;iGet(i).getFullName()); //if (friends. Get(i).getLastPosition()!

=null) // usernames. Add(i,friends. Get(i).getLastPosition().

GetpositiontimeFormated()); // } usernames = new ArrayList(); for(int I = 0 ; I Length ; i++){ usernames. Add(usernames_arrayi); } listAdapter = new ActivityList(InitialActivity. This, android.R.id.

Text1, usernames); // setListAdapter(new ArrayAdapter(this, R.layout. List_item3, usernames)); setListAdapter(listAdapter); ListView lv = getListView(); lv. SetTextFilterEnabled(true); lv.

SetOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { //startActivityForResult(i, 0); } }); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { Bundle bundle = new Bundle(); //bundle is like the letter bundle. PutString ("user", listAdapter. GetItem(position)); //arg1 is the keyword of the txt, arg2 is the txt // bundle.

PutString ("user", friends. Get(position).getFullName()); //arg1 is the keyword of the txt, arg2 is the txt // bundle. PutString ("email", friends.

Get(position).getEmail()); // bundle. PutString ("permission", friends. Get(position).getPermission()); // Intent i=null; // if (friends.

Get(position).getPermission(). Equals("total")) // I = new Intent (AllActivity. This, Locate.

Class); // else if (friends. Get(position).getPermission(). Equals("perhours")) // I = new Intent (AllActivity.

This, LocatePerHours. Class); // else // I = new Intent (AllActivity. This, LocatePerDays.

Class); // // i. PutExtras(bundle); // startActivity(i); } private OnClickListener callBtnListener = new OnClickListener(){ public void onClick(View v) { Log. I("Info","Username: " + v.getTag()); }}; class ActivityList extends ArrayAdapter{ public ActivityList(Context context, int textViewResourceId, ArrayList objects) { super(context, textViewResourceId, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null){ LayoutInflater inflater = LayoutInflater.

From(InitialActivity. This); convertView = inflater. Inflate(R.layout.

New_list_item2, parent, false); holder = new ViewHolder(); holder. Text = (TextView)convertView. FindViewById(R.id.

FriendName); holder. Button = (Button)convertView. FindViewById(R.id.

CallButton); convertView. SetTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } holder.text. SetText(getItem(position)); holder.button.

SetOnClickListener(callBtnListener); holder.button. SetTag( getItem(position) ); return convertView; } } static class ViewHolder{ TextView text; Button button; } } I also deleted the last line (onClick) and add an onClickListener on the list activity. I tested in my device and works, I delete the DataHolder class.

The other things like the Bundle map, Intent, is commented because I think is not your problem. Cheers.

Thanks for your time, im trying to compile your code.... what is android.R.id. Text1 on the line: listAdapter = new ActivityList(InitialActivity. This, android.R.id.

Text1, usernames);? – AndroidUser99 Jan 25 at 22:12 oh, sorry, I forget about that, is a default parameter for the ArrayAdapter constructor, it's needed to instantiate the array adapter (in this textview are placed the ListAdapter item objects.toString() on instantiation time i.e. ), however, when you construct the view for each item in the list, you can use the textview obtained from the inflated view to place the data.

Like holder. Text = (TextView)convertView. FindViewById(R.id.

FriendName); – Franco 9 Jan7 at 0:01 I tryed changuing the line with: listAdapter = new ActivityList(AllActivity. This, R.id. FriendName, usernames); – AndroidUser99 Jan 27 at 10:56 but I still get an error.... it have problems with the third parameter, it needs a ArrayList but I am using List...... how to solve that?

– AndroidUser99 Jan 27 at 10:57 can you change the code to not use DataHolder? It is not compatible with my code – AndroidUser99 Jan 27 at 11:02.

A listactivity with custom list item is made (without quotes):. Make a ListActivity with custom List Item.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions