Android - How to compile a class which has others activities inside - android

I have an ExpandableListView which has a lot of children and for every child I would start an activity. Someone told me to create an unique class with all the activities of every children. Is it possible? How? In my project I have a Child.class, a Group.class, a MyExpandableListView.class, a XmlHandler.class and the main activity. I take the name for the ExpandableList from xml files that are in res/raw folder. I hope someone could help me. Thank you.

If your activities triggered by the ExpandableListView's child click event are similar (I mean only the data they display is different), it's enough for you to have a single activity, and make it's content dynamic based on the selected (clicked) child of the ExpandableListView.
Let's call your new activity Details.
If your main activity doesn't extend ExpandableListActivity, but you have inside a member of type MyExpandableListView myExpandableListView, you should set the `OnChildClickListener on that:
final ExpandableListView myExpandableListView = getExpandableListView();
myExpandableListView.setOnChildClickListener(new OnChildClickListener()
{
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id)
{
final Child selectedChild = groups.get(groupPosition)
.getChildren().get(childPosition);
final Intent intent = new Intent(testactivity.this, Details.class);
intent.putExtra("selectedChild", selectedChild);
startActivity(intent);
return true;
}
});
If your main activity extends ExpandableListActivity, to call the Detail activity, you need to override the onChildClick event of your ExpandableListActivity:
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id)
{
final Child selectedChild = groups.get(groupPosition)
.getChildren().get(childPosition);
final Intent intent = new Intent(this, Details.class);
intent.putExtra("selectedChild", selectedChild);
startActivity(intent);
return true;
}
You add the clicked child's value as an extra to the Details activity's intent by the putExtra method, and then just start the activity.
Inside the Details activity you can retrieve the passed Child (the clicked item on your exp.listactivity) from the activity's Intent using the getSerializableExtra method (for this to work, your Child class must implement java.io.Serializable!).
Details.java:
public class Details extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
final Intent intent = getIntent();
if (intent.hasExtra("selectedChild"))
{
final Child selectedChild = (Child)intent.
getSerializableExtra("selectedChild");
if (selectedChild != null)
{
((TextView)findViewById(R.id.nameText)).
setText(selectedChild.getName());
((ImageView)findViewById(R.id.image)).setImageResource(getResources().
getIdentifier(selectedChild.getImage(), "drawable", "com.test.com"));
}
}
}
}
Your Details activity's layout should contain a text and an image
details.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100dip"
android:orientation="vertical">
<TextView android:id="#+id/nameText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingLeft="10dip" android:textColor="#android:color/white"
android:textSize="30dip" android:gravity="center_vertical|center_horizontal" />
<ImageView android:id="#+id/image"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scaleType="fitCenter" android:layout_below="#id/nameText" />
</RelativeLayout>
By this you can achieve, that when you click on a child item of your ExpandableListActivity, you start a new activity (Details) where the selected Child's image and text are displayed.
If you put more information inside your Child class (or url from where to fetch more data), you can get it more complicated.

Related

OnItemClickListener - changing the click area [duplicate]

So I have a custom ListView object. The list items have two textviews stacked on top of each other, plus a horizontal progress bar that I want to remain hidden until I actually do something. To the far right is a checkbox that I only want to display when the user needs to download updates to their database(s). When I disable the checkbox by setting the visibility to Visibility.GONE, I am able to click on the list items. When the checkbox is visible, I am unable to click on anything in the list except the checkboxes. I've done some searching but haven't found anything relevant to my current situation. I found this question but I'm using an overridden ArrayAdapter since I'm using ArrayLists to contain the list of databases internally. Do I just need to get the LinearLayout view and add an onClickListener like Tom did? I'm not sure.
Here's the listview row 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="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="#+id/UpdateNameText"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:textSize="18sp"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/UpdateStatusText"
android:singleLine="true"
android:ellipsize="marquee"
/>
<ProgressBar android:id="#+id/UpdateProgress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminateOnly="false"
android:progressDrawable="#android:drawable/progress_horizontal"
android:indeterminateDrawable="#android:drawable/progress_indeterminate_horizontal"
android:minHeight="10dip"
android:maxHeight="10dip"
/>
</LinearLayout>
<CheckBox android:text=""
android:id="#+id/UpdateCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
And here's the class that extends the ListActivity. Obviously it's still in development so forgive the things that are missing or might be left laying around:
public class UpdateActivity extends ListActivity {
AccountManager lookupDb;
boolean allSelected;
UpdateListAdapter list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lookupDb = new AccountManager(this);
lookupDb.loadUpdates();
setContentView(R.layout.update);
allSelected = false;
list = new UpdateListAdapter(this, R.layout.update_row, lookupDb.getUpdateItems());
setListAdapter(list);
Button btnEnterRegCode = (Button)findViewById(R.id.btnUpdateRegister);
btnEnterRegCode.setVisibility(View.GONE);
Button btnSelectAll = (Button)findViewById(R.id.btnSelectAll);
btnSelectAll.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
allSelected = !allSelected;
for(int i=0; i < lookupDb.getUpdateItems().size(); i++) {
lookupDb.getUpdateItem(i).setSelected(!lookupDb.getUpdateItem(i).isSelected());
}
list.notifyDataSetChanged();
// loop through each UpdateItem and set the selected attribute to the inverse
} // end onClick
}); // end setOnClickListener
Button btnUpdate = (Button)findViewById(R.id.btnUpdate);
btnUpdate.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
} // end onClick
}); // end setOnClickListener
lookupDb.close();
} // end onCreate
#Override
protected void onDestroy() {
super.onDestroy();
for (UpdateItem item : lookupDb.getUpdateItems()) {
item.getDatabase().close();
}
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
UpdateItem item = lookupDb.getUpdateItem(position);
if (item != null) {
item.setSelected(!item.isSelected());
list.notifyDataSetChanged();
}
}
private class UpdateListAdapter extends ArrayAdapter<UpdateItem> {
private List<UpdateItem> items;
public UpdateListAdapter(Context context, int textViewResourceId, List<UpdateItem> items) {
super(context, textViewResourceId, items);
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = null;
if (convertView == null) {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = li.inflate(R.layout.update_row, null);
} else {
row = convertView;
}
UpdateItem item = items.get(position);
if (item != null) {
TextView upper = (TextView)row.findViewById(R.id.UpdateNameText);
TextView lower = (TextView)row.findViewById(R.id.UpdateStatusText);
CheckBox cb = (CheckBox)row.findViewById(R.id.UpdateCheckBox);
upper.setText(item.getName());
lower.setText(item.getStatusText());
if (item.getStatusCode() == UpdateItem.UP_TO_DATE) {
cb.setVisibility(View.GONE);
} else {
cb.setVisibility(View.VISIBLE);
cb.setChecked(item.isSelected());
}
ProgressBar pb = (ProgressBar)row.findViewById(R.id.UpdateProgress);
pb.setVisibility(View.GONE);
}
return row;
}
} // end inner class UpdateListAdapter
}
edit: I'm still having this problem. I'm cheating and adding onClick handlers to the textviews but it seems extremely stupid that my onListItemClick() function is not being called at all when I am not clicking on my checkbox.
The issue is that Android doesn't allow you to select list items that have elements on them that are focusable. I modified the checkbox on the list item to have an attribute like so:
android:focusable="false"
Now my list items that contain checkboxes (works for buttons too) are "selectable" in the traditional sense (they light up, you can click anywhere in the list item and the "onListItemClick" handler will fire, etc).
EDIT: As an update, a commenter mentioned "Just a note, after changing the visibility of the button I had to programmatically disable the focus again."
In case you have ImageButton inside the list item you should set the descendantFocusability value to 'blocksDescendants' in the root list item element.
android:descendantFocusability="blocksDescendants"
And the focusableInTouchMode flag to true in the ImageButton view.
android:focusableInTouchMode="true"
I've had a similar issue occur and found that the CheckBox is rather finicky in a ListView. What happens is it imposes it's will on the entire ListItem, and sort of overrides the onListItemClick. You may want to implement a click handler for that, and set the text property for the CheckBox as well, instead of using the TextViews.
I'd say look into this View object as well, it may work better than the CheckBox
Checked Text View
use this line in the root view of the list item
android:descendantFocusability="blocksDescendants"

Android 5.0 List Animation

I have a list of items that is composed of a View and a TextView. I defined an animation:
View mView = findViewById(R.id.view);
Intent detailIntent = new Intent(this, DetailActivity.class);
String transitionName = getString(R.string.my_transition);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
mView, transitionName);
startActivity(detailIntent, options.toBundle());
and in my list_item.xml I have:
<View
android:id="#+id/view"
android:layout_width="#dimen/list_dimen"
android:layout_height="match_parent"
android:layout_marginStart="0dp"
android:background="#color/accent"
android:transitionName="#string/my_transition"/>
The transition works fine for the first item, but no matter which item in the list I click, the animation always comes from the first item, and if I scroll to the point where the first item is out of view the app force closes when I click on an item. How do I attach to animation to a specific list item?
SOLUTION:
Per MarcaoAS answer, I had to attach the view to the specific root view. I am implementing a Master-Detail relationship so I have a Fragment for my list which contains a Callbacks :
public interface Callbacks {
public void onItemSelected(String id);
}
I had to edit this to take a View as a parameter instead of a String: onItemSelected(View view).
Likewise, I had to make this change where ever that is referenced. When the Fragment was generated (I selected Master-Detail when creating the project in Android Studio) the onListItemClick was overridden:
#Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
mCallbacks.onItemSelected(view);
}
As you can see I once again replaced the id with the view that is passed in.
In my ListActivity where I have my original code posted above I now have:
#Override
public void onItemSelected(View view) {
//tablet
if (mTwoPane) {
//tablet handling
}
//phone
else {
View mView = view.findViewById(R.id.view);
Intent detailIntent = new Intent(this, DetailActivity.class);
String transitionName = getString(R.string.my_transition);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
mView, transitionName);
startActivity(detailIntent, options.toBundle());
}
}
Once again passing in the View from the Fragment class. This solved my issue.
Make sure that your the code below is returning the item view.
View mView = findViewById(R.id.view);
If you are calling this from an activity it will always return the first item because your items may have the same id. Try to do that in your onClick method:
public void onClick(View v) {
View mView = v.findViewById(R.id.view);
Intent detailIntent = new Intent(this, DetailActivity.class);
String transitionName = getString(R.string.my_transition);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, mView, transitionName);
startActivity(detailIntent, options.toBundle());
}

Detecting click on image in ExpandableListView group

I have an image inside my group_row
<?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="horizontal"
android:background="#8fbfff" >
<TextView
android:id="#+id/tv_category_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView"
android:layout_weight="1" />
<ImageView
android:id="#+id/img_add_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_add_item"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp" />
</LinearLayout>
I want to detect when this image was clicked and the id of the Group, and then StartActivityForResult. I was able to do it inside my custom ExpandableListView_Adapter:
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final Category category = arr_categories.get(groupPosition);
convertView = inflater.inflate(R.layout.row_category, parent, false);
((TextView)convertView.findViewById(R.id.tv_category_name)).setText(category.getCategory_name());
ImageView img_add = (ImageView) convertView.findViewById(R.id.img_add_category);
img_add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "Add item to category: "+category.getCategory_id(), Toast.LENGTH_LONG).show();
// Declare on intent to use Add/Edit Note activity
Intent open_add_new_item = new Intent(context, Activity_Add_Edit_Base_Item.class);
// Pass the currently selected category ID to the Intent
open_add_new_item.putExtra("CURR_ITEM_CATEGORY", category.getCategory_id());
// Start the activity
((Activity) context).startActivityForResult(open_add_new_item, Constants.Request_Codes.REQUEST_CODE_CREATE_NEW_ITEM);
}
});
return convertView;
}
This works just fine. However, If there's a possibility to do so, I'd like to separate this image click detection from the Adapter and do it in my fragment (I think it'll be easier to implement OnActivityResult this way). I tried to do it by setting OnGroupClickListener for my ExpandableListView:
master_lv.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
final Category c = arr_all_categories.get(groupPosition);
ImageView img_add = (ImageView) v.findViewById(R.id.img_add_category);
img_add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//Category c = arr_all_categories.get(groupPosition);
Toast.makeText(getActivity(), "group position: "+c.getCategory_id(), Toast.LENGTH_LONG).show();
// Declare on intent to use Add/Edit Note activity
Intent open_add_new_item = new Intent(getActivity(), Activity_Add_Edit_Base_Item.class);
// Pass the currently selected category ID to the Intent
open_add_new_item.putExtra("CURR_ITEM_CATEGORY", c.getCategory_id());
// Start the activity
startActivityForResult(open_add_new_item, Constants.Request_Codes.REQUEST_CODE_CREATE_NEW_ITEM);
}
});
return false;
}
});
However this didn't work at all: I'm not getting the Toast message and the Intent doesn't fire.
Is it possible to do so? If it is - how? Thanks!
The first one you need to do is set clickable=true to root layout of the custom cell xml.
After that, what we are going to do is Custom Event Raising. We will use interfaces.
Create a interface class
Example :
public interface OnImageClickListener {
public void onImageClicked();
}
Then create a instance in adapter
public OnImageClickListener mListener;
Also set OnClickListener to imageview in getView method of the adapter and add the following line in OnClick method.
mListener.OnImageClicked();
Lastly, in Activity;
mAdapter.mListener = new OnImageClickListener();
Magic will happen here :)
or you can implement this interface like
public MyActivity implements OnItemClickListener and let the implement methods.
Then you can
mAdapter.mListener = this;
Good luck there :)

Convert my application to Fragments: How to handle activities?

I'm planning to convert an existing android application to fragments layout.
The idea is to have the classical two panel layout (item list on left, and details on right).
Actually the application is composed by 4 activites:
A ChoiceListActivity with all the available options
3 different activities, one for each operation available on the tool.
Now i started to work on the conversion and i created a FragmentActivity classs, that is the main class:
public class MainFragment extends FragmentActivity {
private static final String TAG = "MainFragment";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
if(findViewById(R.id.fragment_container)!=null){
Log.i(TAG, "No Tablet");
Intent i = new Intent(MainFragment.this, main.ChoiceActivity.class);
startActivity(i);
} else {
Log.i(TAG, "Tablet");
}
}
}
And i created a ChoiceListFragment:
`
public class ChoiceListFragment extends ListFragment {
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(getActivity(), getListView().getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
super.onListItemClick(l, v, position, id);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String[] options = getResources().getStringArray(R.array.listitems);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(inflater.getContext(), R.layout.list_item, options);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
}
That fragment will be the left side of the panel.
My problem is for the right side. The idea is that for every element of the list the corresponding activity (or fragment?) will be shown.
So what is the correct way?
Is a good idea to start an activity in the right fragment when the user select an item?
Or i must switch between fragments programmatically? And how to do that (i found many tutorials, but they use always the same activity for the right panel changing some data inside it)?
I have created the following class for the right fragment (but i'm not sure that i'm doing it correctly):
public class RightFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.main, container, false);
}
}
I noticed that i can eventually change the layout using the LayoutInflater object during onCreate method, but this simply siwtch the layout on the screen, The objects declared in the layout aren't initialized (nor eventListener added, etc). So how to do that?
Maybe i should Create an Intent and use startActivity to launch the existing activities, or this is a bad idea into a fragment?
Actually the xml layout is:
<?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="horizontal" >
<fragment
android:id="#+id/choicelist_fragment"
android:name="main.fragments.ChoiceListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/right_fragment"
android:name="main.fragments.RightFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
Ok i found myself the solution, it was not clear on a first moment, but reading some documentation, looking at many tutorials maybe i understand how it works.
First of all i removed the second fragment *right_fragment* from the layout (check the question), i replaced it with an empty FrameLayout called *activity_container* that will be the container of my fragments.
The idea behind is simply use the FragmentManager to replace the fragment inside the container.
So i updated the onListItemClick method into the ChoiceListFragment, and depending on what is the list item tapped, it creates a new Fragment and replace it into the *activity_container*. The updated method is similar to the following:
public void onListItemClick(ListView l, View v, int position, long id) {
String itemName = getListView().getItemAtPosition(position).toString();
switch(position){
case OPTION_ONE: getFragmentManager().beginTransaction().replace(R.id.activity_container, new OptionOneFragment()).commit();
break;
case RESISTOR_VALUE:
getFragmentManager().beginTransaction().replace(R.id.activity_container, new OptionTwoFragment()).commit();
break;
default:
Toast.makeText(getActivity(), getListView().getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
break;
}
super.onListItemClick(l, v, position, id);
}
In that way every component of the application has its own fragment, handled by a different class.
You're on the right track. On small screens, clicking a list item starts a DetailActivity, which is a simple wrapper around a DetailFragment. On a larger screen, clicking the list item would replace the right hand side with a new instance of DetailFragment.
If you are using eclipse and ADT, I would suggest taking a look at the MasterDetailFlow template, which can be accessed by creating a new Android project or a new Android Activity.

OnItemClickListener and OnClickListener in ListView

I have a custom view for each row in a custom ListAdapter and I am trying to perform onClick action and get the row position in the list where the click came from.
<?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:paddingLeft="10dip" android:id="#+id/itemRoot" android:clickable="false">
<TextView android:layout_width="wrap_content" android:text="TextView"
android:layout_height="wrap_content" android:id="#+id/itemTxt"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"></TextView>
<TextView android:layout_toRightOf="#+id/itemTxt" android:text="TextView"
android:layout_height="wrap_content" android:layout_alignBottom="#+id/itemTxt"
android:id="#+id/amountTxt" android:paddingLeft="6dip"
android:layout_centerVertical="true" android:layout_width="match_parent"></TextView>
<ImageView android:id="#+id/delBtn" android:layout_height="wrap_content"
android:src="#drawable/delete" android:layout_width="wrap_content"
android:layout_alignParentRight="true" android:paddingRight="10dip"
android:layout_centerVertical="true"></ImageView>
</RelativeLayout>
I want to figure out when TextView or ImageView is clicked, I also need to know what row in the list it came form. I have tried using OnItemClickListener and it works fine to get the row where the click comes from. However, once I register an OnClick listener for the views, the onItemClicked() method gets skipped and onClick() is executed straight away, but there is no way of getting the row position that the view is in(or at least not that I know if).
If I set clickable to false for the views, then onItemClicked get called and I tried manually calling performClick() on the given view. But this only works for the root element (RelativeLayout), and if click comes from TextView inside the layout the click doesn't propagate.
I can't really figure out how to get both position in the list and perform onClick action.
Any thoughts are welcome.
Alex
You could assign the proper OnClickListener to each ImageView and TextView from inside your ListAdapter's overridden getView method.
Inside that method you know the item's position, so you can pass it to the custom listener classes, and use it there as you want:
#Override
public View getView(final int position, View convertView, ViewGroup parent)
{
// TODO: instantiate the layout
// here I call a super method
final View view = super.getView(position, convertView, parent);
final TextView textView = (TextView)view.findViewById(R.id.itemTxt);
textView.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
Log.i("Click", "TextView clicked on row " + position);
}
});
final ImageView imageView = (ImageView)view.findViewById(R.id.delBtn);
imageView.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
Log.i("Click", "ImageView clicked on row " + position);
}
});
return view;
}
The other possible option to have the OnClickListener in the same class as the creating activity is to add to the activity implements OnItemClickListener.
public class DisplayListCustom extends Activity implements OnItemClickListener
Then set the custom list to listen
ListView list = (ListView)findViewById(R.id.custom_list);
list.setClickable(true);
list.setOnItemClickListener(this);
list.setAdapter(new CustomListAdapter(getApplicationContext(), listItems));
Finally in the onItemClick return, you can find the inner views by using resource ID
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
LinearLayout listItem = (LinearLayout) v;
TextView clickedItemView = (TextView) listItem.findViewById(R.id.name);
String clickedItemString = clickedItemView.getText().toString();
Log.i("DisplayListCustom", "Click detected " + clickedItemString + ", position " + Integer.toString(position));
This is the solution I went with. I used LinearLayout for my custom layout container, but I assume the same applies to RelativeLayout.
You need to extend your TextView etc, override the click method, do the appropriate actions and then the trick is to return false so it's then propagated to the listview.

Categories

Resources