Touchable listview

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Touchable listview

Postby wk » Tue Jul 15, 2008 6:04 pm

Hi,

I have a huge problem with making touchable listview. I tried 200 solutions without results. The most logical for me is something like this:

SomeActivity.java

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class SomeActivity extends ListActivity
  3.  
  4. {
  5.  
  6.     protected void onCreate(Bundle icicle)
  7.  
  8.     {  
  9.  
  10.        super.onCreate(icicle);
  11.  
  12.        TouchList tl = new TouchList(this);
  13.  
  14.        LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);      
  15.  
  16.        tl.setLayoutParams(lp);
  17.  
  18.  
  19.  
  20.        LinearLayout currentLay = (LinearLayout) findViewById(R.id.some_layout_linear);
  21.  
  22.        currentLay.addView(tl,0);      
  23.  
  24.  
  25.  
  26.        setContentView(R.layout.some_layout);
  27.  
  28.  
  29.  
  30. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



TouchList

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class TouchList extends ListView
  2.  
  3. {
  4.  
  5.     public TouchList(Context context) {
  6.  
  7.          super(context);
  8.  
  9.          this.setId(android.R.id.list);
  10.  
  11.          this.setFocusable(true);
  12.  
  13.          this.setFocusableInTouchMode(true);
  14.  
  15.     }
  16.  
  17.  
  18.  
  19.     public boolean onTouchEvent(MotionEvent event)
  20.  
  21.         {
  22.  
  23.                 // some code here
  24.  
  25.         }
  26.  
  27. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



some_layout.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.  
  4.         android:orientation="vertical" 
  5.  
  6.         android:layout_width="wrap_content"
  7.  
  8.         android:layout_height="wrap_content"
  9.  
  10.         android:id="@+id/some_layout_linear"
  11.  
  12.         >
  13.  
  14.        
  15.  
  16.         <TextView
  17.  
  18.                 android:id="@android:id/empty"
  19.  
  20.                 android:layout_width="wrap_content"
  21.  
  22.                 android:layout_height="fill_parent"
  23.  
  24.                 android:text="No items"
  25.  
  26.         />
  27.  
  28. </LinearLayout>
  29.  
  30.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


And of course it doesn't wok - there are a couple errors in first class - the best will be if someone can simply run it on own emulator and see - because is hard to write some more informations about errors.

In example above I'm trying to create listview with "list" id and then add it on first (0) position of linearlayout, which exists in xml file. A tried also couple other ways, but without good result - can You help me?

All I want to do is access to "onTouchEvent" of listview in ListActivity.

Thank You for any help.
wk
Freshman
Freshman
 
Posts: 2
Joined: Tue Jul 15, 2008 5:50 pm

Top

Postby noname » Thu Jul 17, 2008 12:14 am

To implement a list click listener you should override the onListItemClick method of the ListActivity class.
This worked for me
noname
Freshman
Freshman
 
Posts: 2
Joined: Thu Jul 17, 2008 12:00 am

Postby wk » Thu Jul 17, 2008 9:46 am

I founded working solution:

It's using onInterceptTouchEvent on parent layout - which can be i.e. extended Linear Layout.
wk
Freshman
Freshman
 
Posts: 2
Joined: Tue Jul 15, 2008 5:50 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 10 guests