I'm using this CoverFlow :
http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html
I want to be able to change View when I click on a button, the button being a back/forward icon which will take you to the previous/next item in the coverflow.
I have modded the coverflow slightly so that I use an XML layout instead.
Here is my onCreate() method:
setContentView(R.layout.main);
CoverFlow coverFlow = (CoverFlow)findViewById(R.id.coverflow);
coverFlow.setAdapter(new ImageAdapter(this));
ImageAdapter coverImageAdapter = new ImageAdapter(this);
coverFlow.setAdapter(coverImageAdapter);
coverFlow.setSpacing(-20);
coverFlow.setSelection(0, true);
coverFlow.setAnimationDuration(1000);
tv = (TextView)findViewById(R.id.textView1);
coverFlow.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getBaseContext(), String.valueOf(arg2), Toast.LENGTH_SHORT).show();
}
});
coverFlow.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
tv.setText(String.valueOf(arg2));
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do something
}
});
My 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="fill_parent"
android:background="#drawable/home_background"
android:orientation="vertical" >
<com.demo.app.coverflow.CoverFlow
android:id="#+id/coverflow"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="39dp"
android:layout_marginLeft="35dp"
android:background="#drawable/button_left" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="39dp"
android:layout_marginRight="35dp"
android:background="#drawable/button_right" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="55dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="hello"
android:textColor="#color/White"
android:textSize="16dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="170dp"
android:layout_marginTop="15dp"
android:src="#drawable/unsa_logo" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:layout_marginTop="23dp"
android:src="#drawable/pnc_logo" />
</RelativeLayout>
Thanks David, I'm one of the Mike colleagues but I've never written a line of Java.
I work in the iOS department of our company.
I understood what you were talking about. Your answer was helpful and well written!
I just had to add :
if ( currentimageposition < coverFlow.getcount()-1) {
coverFlow.setSelection(currentImagePosition +1, true);
currentImagePosition = currentImagePosition +1;
}
Because your onItemSelected was not called (update the current marker), I don't know why.
However, coverFlow.selection( int , bool) is not animated. It is just a set method when the view is loaded. For example, coverFlow.selection(3,true) will set the fourth image on the center of the coverflow.
While I was trying to find out how to add the animation I came across this which does everything in just one line :
go left
coverFlow.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0));
go right
coverFlow.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, new KeyEvent(0, 0));
(just add each line to their respective button onclick methods
Hope this can help anyone else who finds them self in the same situation as I was :)
I hope i understand your question. if so, here's an idea:
you need to store a private instance variable that tracks the current position of the image that is being displayed from the coverflow. then, you update it from the setOnItemSelectedListener() method, which is inherited from Gallery. On the "back" or "forward" button, you simply set your current selection +/- 1 depending on the button pressed.
so in your Activity, add an instance variable int that will keep track of position like...
public class MyActivity {
private int currentImagePosition = -1;
//add the rest of your onCreate code here...
}
Next, you need to be able to update the current position of the image that is currently being displayed in the coverflow. you can do so by overriding setOnItemSelectedListener like so (inside your onCreate method):
coverFlow.setOnItemSelectedListener(new OnItemSelectedListener(){
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
currentImagePosition = position; //this will update your current marker
}
};
Lastly, all you have to do is set each button's onclick listeners to change to the previous or next image by using setSelection( currentImagePosition+1 ) or setSelection( currentImagePosition-1 ). By the way, what's the true or false parameter of setSelection() do? i'm not sure what it does so i'm just going to use true like you did initially. your onCreate() method will now look something like:
#Override
public void onCreate(Bundle savedInstanceState){
//insert your other code in onCreate here in this spot....
//add the following lines to your code:
Button goLeft = (Button) findViewById(R.id.button1);
goLeft.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
//go to previous image
if( currentImagePosition > 0 ){ //i'm assuming you dont want to go left anymore once at the leftmost image
coverFlow.setSelection(currentImagePosition - 1, true);
}
}
} ) ;
Button goRight = (Button) findViewById(R.id.button2);
goRight.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
//go to previous image
if( currentImagePosition < coverFlow.getCount()-1 ){ //i'm assuming you dont want to go left anymore once at the leftmost image
coverFlow.setSelection(currentImagePosition + 1, true);
}
}
} ) ;
}
NOTE: the part about updating position is assumed to work from reading Get the position of the current image displayed in Gallery so i hope this works. if not, at least i tried :D
Good luck!!!
Related
I have a set of image view that I want to change when it is clicked. The first view is set by default, and I want the second one to appear when the first one is clicked. I also want the reverse to occur when the second one is visible. How can I do this? (Example: Default is Img 1 default, img 2 hidden. On click, img 2 shows, img 1 is hidden. On click again, reverse occurs).
<ImageView
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_alarm_off_75dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="134dp" />
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_alarm_on_75dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:layout_marginTop="134dp" />
Use the Following Code:
ImageView img1=(ImageView)findViewById(R.id.img1);
ImageView img2=(ImageView)findViewById(R.id.img2);
img1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
img1.setVisibility(View.GONE);
img2.setVisibility(View.VISIBLE);
}
});
img2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
img2.setVisibility(View.GONE);
img1.setVisibility(View.VISIBLE);
}
});
in both of button onclick you must check to see if other button is not visible then set it visible and if it is visible then do not do any thing. you can check visibility of buttons with this code
if(mybutton.getVisibility()==View.VISIBLE)
{
//set visibiliy of mybutton
}
I want to get the text of a TextView that is in a ListView's item.
See the code and you will find what's my question.
Activity.java:
SimpleAdapter adapter = new SimpleAdapter(
rootView.getContext(),
result,
R.layout.article_list_item,
new String[]{"article_title", "article_PubDate", "article_category", "article_articleNo"},
new int[]{R.id.article_title, R.id.article_PubDate, R.id.article_category, R.id.article_articleNo});
ListView articleItem.setAdapter(adapter);
articleItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//I want get the text of R.id.article_articleNo(see article_list_item.xml)?
//What should I do?
}
});
article_list_item.xml :
<?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"
android:id="#+id/article">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="文章标题"
android:id="#+id/article_title"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30-Apr-2014"
android:id="#+id/article_PubDate"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="personal_finance"
android:id="#+id/article_category"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9312"
android:id="#+id/article_articleNo"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20dp"/>
</LinearLayout>
</LinearLayout>
That's all!!
I want to get the text of R.id.article_article (see article_list_item.xml).
How can I do it?
Does this work for you?
articleItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String text = result.get(position).get("article_articleNo");
//^^ does not necessarily need to be a string,
// make this whatever data type you are storing in the map
}
});
The idea is that in your SimpleAdapter, you are populating your ListView with a List<Map<String,Object>> (in this case named result).
Therefore, you can get that specific Map<String,Object> from the List by using .get(position), then once again using .get("article_articleNo") to get the Object from the map.
Edit after seeing your comment: Try this:
articleItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView tv = (TextView) view.findViewById(R.id.article_articleNo);
String text = tv.getText().toString();
}
});
First of all, forget about the xml layout. It's just a placeholder for data, which is used to define the layout of the data, and has got nothing to do with storing the data.
Now, your problem statement can be re-stated as: how to fetch data from an array (or list or arraylist or whatever the format of your result is) on clicking list item.
Hmm. Sounds simple now.
Refer to #RougeBaneling's answer for technical details.
I need to use spinner as a menu. But problem is that when I click on an item it gets selected and shown at that place a behavior which I want to avoid. Secondly I need that the very first item should always be a heading no matter which of the items has been selected as in the following images:
spinner in normal condition
when user taps the spinner
Now if user taps any of the items heading should not be changed but item should be selected. I have achieved it using ListView but I think I must use proper Android components (if it is really possible).
Thanks in advance.
I have solved the above issue using the following code, but need to use spinner.
layout file
<RelativeLayout
android:id="#+id/header_main"
style="#style/layout_f_w"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="#color/heading_color" >
<TextView
android:id="#+id/headingText"
style="#style/layout_wrap"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="MATCH CENTER"
android:textColor="#color/text_color_white"
android:textSize="15sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/matchcenter_menu"
style="#style/layout_wrap"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/headingText"
android:background="#android:color/transparent"
android:paddingTop="20dp"
android:src="#drawable/drp_down_menu" />
</RelativeLayout>
....
<ListView
android:id="#+id/mainscreen_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:cacheColorHint="#00000000"
android:divider="#android:color/white"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"
android:listSelector="#android:color/transparent" />
Setting the views.
TextView headingText = (TextView)findViewById(R.id.headingText);
headingText.setTypeface(Utils.getCustomFont(LiveScoreCrowdScreen.this));
headingText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showMatchCenterMenu(v);
}
});
....
matcheCenterMenu = (ImageButton)findViewById(R.id.matchcenter_menu);
matcheCenterMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showMatchCenterMenu(v);
}
});
....
mainscreenMenu = (ListView)findViewById(R.id.mainscreen_menu);
....
public void showMatchCenterMenu(View btn) {
ScreenMenuItemsAdapter adapter = null;
mainscreenMenu = (ListView)findViewById(R.id.mainscreen_menu);
adapter = new ScreenMenuItemsAdapter(LiveScoreCrowdScreen.this, getResources().getStringArray(R.array.livescorecard_menuitems));
mainscreenMenu.setAdapter(adapter);
mainscreenMenu.setVisibility(View.VISIBLE);
mainscreenMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View row, int position, long id) {
CCApplication.isMenuOpened = false;
switch (position) {
case 0:// Refresh
//refresh screen
break;
case 1:// Highlights
//get highlights
break;
case 2:// Preferences
//get preferences
break;
case 3:// current time
// get current time
break;
}
mainscreenMenu.setVisibility(View.GONE);
}
});
}
just a hacking solution not proper one:
Again set the adapter with the spinner when you done all works in side onItemSelectedListener().
i.e
spinner.setAdapter(your_adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parentView,
View selectedItemView, int position, long id) {
//Do works here
//atlast again load the same adapter
spinner.setAdapter(your_adapter);
}
}
#Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
It will load the same adapter after selecting an item and show you like before.
please refer this image https://www.dropbox.com/s/6zoj9lw10oc07xa/to_dropbox.png
what i am doing :
i am creating a list_view , in which i am adding custom adapter .
what i am using :
i am using , listView , customAdapter , menuitem .
listView : single listview in whole application
customadapters : 3 custom adapters
menuitem : 1
How i am implementing :
i have data base from which things are fetched properly , and from that database i have entered these values in my listview by filtering that data in 3 types :
1st adapter_type is entered by default ( in onCreate ) .
adapter = new Adapter_forCompletedReminder( array_today_title , this) ;
ls.setAdapter(adapter) ;
2nd adapter_type is entered in my listview by pressing menuitem .
adapter = new Adapter_forCompletedReminder( array_past_2_day_title , this) ;
ls.setAdapter(adapter) ;
3rd adapter_type is entered in my listview by pressing menuitem .
adapter = new Adapter_forCompletedReminder( array_other_day_title , this) ;
ls.setAdapter(adapter) ;
what is my problem :
this code is added inside onCreate() method .
ls.setOnItemClickListener( new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> adapterView , View view , int position ,long arg3)
{
Log.i("Item clicked","tushar:itemclicked") ;
}
});
when i have tried to implement AdapterView.OnItemClickListener() , it is not working ...
code is not crashing ( no red lines in log cat ).
code is not executing in the click of llist_view_element
thanks , for reading my problem .
You use checkbox in customview_completedxml_listview.xml that is why onItemClick listener is not working. If you set clickable = "false" in checkbox then onItemclick listener will work.
If you want want that checkbox will stil work then you have to set onclicklistener event in you custom adapter class.
// I edit getView
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = LayoutInflater.from(ob) ;
View v = inflater.inflate(R.layout.customview_completedxml_listview, null ) ;
TextView txt = ( TextView ) v.findViewById(R.id.txt_fordisplayingdata) ;
txt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(ob, "Hello", Toast.LENGTH_SHORT).show();
}
});
txt.setText(recieved_Array[position]) ;
return v ;
}
///////////////////////
// Second solution set android:focusable="false" in checkbox
<?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"
>
<TextView
android:id="#+id/txt_fordisplayingdata"
android:layout_width="240dp"
android:text="display data"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="#+id/txt_fordisplayingLargerdata"
android:layout_width="240dp"
android:text="display data larger bahut larger "
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:visibility="gone"
/>
<View
android:layout_width="2dp"
android:layout_toRightOf="#id/txt_fordisplayingdata"
android:layout_height="15dp"
android:layout_marginLeft="15dp"
android:layout_centerVertical="true"
android:id="#+id/view_forcompletedtask"
/>
<CheckBox
android:layout_toRightOf="#id/view_forcompletedtask"
android:id="#+id/checkbox_tocomplete"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:focusable="false"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
</RelativeLayout>
Here are few things you can try :-
If there is any button(or checkbox) or any element in your listview item which handles click event then do this for each element:-
android:focusable = "false"
android:focusableInTouchMode = "false"
Try setting this
list.setItemsCanFocus(false);
Override the onItemClick() method
ls.setOnItemClickListener( new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> adapterView , View view , int position ,long arg3)
{
Log.i("Item clicked","tushar:itemclicked") ;
}
});
I really can't say what exactly problem you have, but I wrote very simple example for you. Try it, and if it works - just port your current project into my sample project. https://docs.google.com/file/d/0Bz4Xd7Ju_kbYbVlyd1dvYTJZYTg/edit?usp=sharingalways
P.S.: I recommend you to read about "best practices in Android", when you finish your idea ( about ViewHolder pattern).
I a new to Android development, so this is kind of a basic question.
I would like to implement the same behavior as in the Contacts app. You have a ListView with a series of Contacts | phone icons. There you have one behavior when you click on the contact name, and another behavior when you click on the phone icon.
Here is my code.
Any help is much appreciated.
In summary, what is wrong with the approach
switch (v.getId()) {
case R.id.imageButtonAction:
Activity Class
public class CompaniesActivity extends Activity {
MyApp app;
ListView listCompanies;
Cursor cursor;
// Adapter and its corresponding FROM and TO statements. The number and sequence of the arguments must match in FROM / TO arguments.
SimpleCursorAdapter adapter;
static final String[] FROM = { MenuNavigationData.C_COMPANY, MenuNavigationData.C_DESCRIPTION};
static final int[] TO = { R.id.textCompany, R.id.textDescription }; //
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.companies);
//Gets a reference to the application
app = (MyApp) getApplication();
// Find your views
listCompanies = (ListView) findViewById(R.id.listCompanies);
addButton = (Button) findViewById(R.id.buttonAdd);
// Add actions to user interaction
listCompanies.setOnItemClickListener(new OnItemClickListener() {
#Override
**public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
switch (v.getId()) {
case R.id.imageButtonAction:
startActivity(new Intent(app, InstructionsActivity.class));
break;
default:
int i = adapter.getItemViewType(position);
startActivity(new Intent(app, EditMenuNavigationActivity.class));
break;
}**
}
});
}
Activity xml
<!-- Companies ListView-->
<ListView android:id="#+id/listView1" android:layout_height="wrap_content" android:layout_width="match_parent"></ListView>
<ListView
android:id="#+id/listCompanies"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:background="#5555"/>
</LinearLayout>
Row xml
android:background="#ffff"
android:padding="6dip">
<!-- Company TextView -->
<TextView
android:id="#+id/textCompany"
android:text="TIM"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="#c000"
android:textStyle="bold"
android:textSize="25sp"/>
<!-- Description TextView -->
<TextView
android:id="#+id/textDescription"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#id/textCompany"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentLeft="true"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="#c000"></TextView>
<!-- Action ImageView -->
<ImageView
android:id="#+id/imageButtonAction"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:background="#drawable/icon"/>
</RelativeLayout>
Your onItemClick() callback receives both the specific view as well as its position (0-based), each of these can help you decide which view was clicked. The position is an index into the items you've added, and for more complicated scenarios you can view.setTag(Object o), and use getTag() to retrieve it from your callback.
New much better approach to solve this issue elegantly, and with less code!!!
With the following modifications, the User interface is much more responsive, no more double-clicking issues. :)
Much, much less code that simply works!
Modifications to Row xml
Insert a Linear layout to wrap both the
In this Linear layout, insert a tag named android:onClick="editCompanyClick"
This is the click handler that will be called in the Activity.
Insert a Linear layout to wrap the
In this Linear layout, insert a tag named android:onClick="dialClick"
This is the click handler that will be called in the Activity.
Modifications to Activity class
Remove the previous code
listCompanies.setOnItemClickListener(new OnItemClickListener() { #Override public void onItemClick(AdapterView arg0, View v, int position, long id) {
TextView company = (TextView) v.findViewById(R.id.textCompany);
ImageView dial = (ImageView) v.findViewById(R.id.imageButtonDTMFDial);
company.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(app, EditMenuNavigationActivity.class));
}
});
dial.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(app, InstructionsActivity.class));
}
});
}
Insert the code
public void dialClick(View v) {
startActivity(new Intent(app, InstructionsActivity.class));
}
public void editCompanyClick(View v) {
startActivity(new Intent(app, EditMenuNavigationActivity.class));
record
}
Row xml
<?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="?android:attr/listPreferredItemHeight"
android:padding="6dip" android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout1"
android:orientation="vertical"
android:onClick="editCompanyClick"
android:layout_weight="1">
<!-- Company TextView -->
<TextView android:singleLine="true" android:text="TIM" android:id="#+id/textCompany" android:ellipsize="marquee" android:layout_height="wrap_content" style="#android:style/TextAppearance.Medium" android:layout_width="match_parent" android:gravity="top"></TextView>
<!-- Description TextView -->
<TextView android:singleLine="true" android:text="Chamar atendente" android:id="#+id/textDescription" android:ellipsize="marquee" android:layout_height="wrap_content" style="#android:style/TextAppearance.Small" android:layout_width="match_parent" android:gravity="bottom"></TextView>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:id="#+id/linearLayout2"
android:onClick="dialClick"
android:layout_width="wrap_content" android:layout_gravity="right">
<!-- DTMFDial ImageView -->
<ImageView android:layout_height="wrap_content" android:background="#drawable/icon" android:id="#+id/imageButtonDTMFDial" android:layout_gravity="right" android:layout_width="wrap_content"></ImageView>
</LinearLayout>
</LinearLayout>
I finally found a solution.
This solves the issue. But adds another one. As expected, the ListView now behaves differently when the user clicks on different views(either TextView or ImageView).
But it seems unresponsive. I have to "double-click" in order to trigger either the company.setOnClick or dial.setOnClick. Any suggestions?
// Add actions to user interaction
listCompanies.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
TextView company = (TextView) v.findViewById(R.id.textCompany);
ImageView dial = (ImageView) v.findViewById(R.id.imageButtonDTMFDial);
company.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(app, EditMenuNavigationActivity.class));
}
});
dial.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(app, InstructionsActivity.class));
}
});
}