Search Results

Search found 135 results on 6 pages for 'listactivity'.

Page 1/6 | 1 2 3 4 5 6  | Next Page >

  • Android: Adding static header to the top of a ListActivity

    - by GrandPrix
    Currently I have a class that is extending the ListActivity class. I need to be able to add a few static buttons above the list that are always visible. I've attempted to grab the ListView using getListView() from within the class. Then I used addHeaderView(View) to add a small layout to the top of the screen. Header.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="fill_parent" > <Button android:id="@+id/testButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Income" android:textSize="15dip" android:layout_weight="1" /> </LinearLayout> Before I set the adapter I do: ListView lv = getListView(); lv.addHeaderView(findViewById(R.layout.header)); This results in nothing happening to the ListView except for it being populated from my database. No buttons appear above it. Another approach I tried as adding padding to the top of the ListView. When I did this it successfully moved down, however, if I added any above it, it pushed the ListView over. No matter what I do it seems as though I cannot put a few buttons above the ListView when I used the ListActivity. Thanks in advance. synic, I tried your suggestion previously. I tried it again just for the sake of sanity, and the button did not display. Below is the layout file for the activity and the code I've implemented in the oncreate(). //My listactivity I am trying to add the header to public class AuditActivity extends ListActivity { Budget budget; @Override public void onCreate(Bundle savedInstanceState) { Cursor test; super.onCreate(savedInstanceState); setContentView(R.layout.audit); ListView lv = getListView(); LayoutInflater infalter = getLayoutInflater(); ViewGroup header = (ViewGroup) infalter.inflate(R.layout.header, lv, false); lv.addHeaderView(header); budget = new Budget(this); /* try { test = budget.getTransactions(); showEvents(test); } finally { } */ // switchTabSpecial(); } Layout.xml for activity: <?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="fill_parent"> <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@android:id/empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/empty" /> </LinearLayout>

    Read the article

  • Android ListActivity OnListItemClick error with Webviews

    - by Tista
    I've been figuring how to popup a webview all day when a row in my ListActivity is clicked. I can't even show a Toast when it's clicked. Need help I'm still new with Android, a web developer trying to learn. Thanks before. package com.mf.ar; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.AlertDialog; import android.app.ListActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ArrayAdapter; import android.widget.Toast; public class ListViewer extends ListActivity { private String mJSON; private String[] listRows; private String[] listRowsURI; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.listview); Bundle the = getIntent().getExtras(); this.mJSON = the.getString("JSON"); Log.i("ListViewIntentJSON", this.mJSON); try { JSONObject UrbJSON = new JSONObject(mJSON); JSONObject UrbQuery = UrbJSON.getJSONObject("query"); int rows = UrbQuery.getInt("row"); Log.i("UrbRows", String.format("%d",rows)); JSONArray resultArray = UrbJSON.getJSONArray("result"); this.listRows = new String[rows]; for(int i=0; i<rows; i++) { this.listRows[i] = resultArray.getJSONObject(i). getString("business_name").toString(); } this.listRowsURI = new String[rows]; for(int i=0; i<rows; i++) { this.listRowsURI[i] = resultArray.getJSONObject(i). getString("business_uri_mobile").toString(); } } catch(JSONException e) { e.printStackTrace(); } this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ListViewer.this.listRows)); } @Override protected void onListItemClick(android.widget.ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); String theURI = ListViewer.this.listRowsURI[position].toString(); /*String theURI = ListViewer.this.listRowsURI[position].toString(); //String theURI = "http://www.mediafusion.web.id"; WebView webview = new WebView(this); //setContentView(webview); //addContentView(webview, null); webview.getSettings().setJavaScriptEnabled(true); getWindow().requestFeature(Window.FEATURE_PROGRESS); final Activity activity = this; webview.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { // Activities and WebViews measure progress with different scales. // The progress meter will automatically disappear when we reach 100% activity.setProgress(progress * 1000); } }); webview.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); } }); webview.loadUrl(theURI);*/ Toast.makeText(ListViewer.this.getApplicationContext(), theURI, Toast.LENGTH_SHORT); } }

    Read the article

  • Android: ListActivity design - changing the content of the List Adapter

    - by Rob
    Hi, I would like to write a rather simple content application which displays a list of textual items (along with a small pic). I have a standard menu in which each menu item represents a different category of textual items (news, sports, leisure etc.). Pressing a menu item will display a list of textual items of this category. Now, having a separate ListActivity for each category seems like an overkill (or does it?..) Naturally, it makes much more sense to use one ListActivity and replace the data of its adapter when each category is loaded. My concern is when "back" is pressed. The adapter is loaded with items of the current category and now I need to display list of the previous category (and enable clicking on list items too...). Since I have only one activity - I thought of backup and load mechanism in onPause() and onResume() functions as well as making some distinction whether these function are invoked as a result of a "new" event (menu item selected) or by a "back" press. This seems very cumbersome for such a trivial usage... Am I missing something here? Thanks, Rob

    Read the article

  • Android - ListActivity, add Header and Footer view

    - by Victor
    I'm using ListActivity, listview. listView = getListView(); just working perfectly. I added footer view as LayoutInflater inflater = getLayoutInflater(); listView.addFooterView( inflater.inflate( R.layout.footer, null ), null, false); and everything was shiny but ugly, so i wanted to add this footer view (which contains only 1 edittext and only 1 button ) to header of listView as LayoutInflater inflater = getLayoutInflater(); listView.addHeaderView( inflater.inflate( R.layout.footer, null ), null, false); and suddenly everything goes wrong, and i get RuntimeException immediately. Suspended(exception RuntimeException) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) ActivityThread.access$2200(ActivityThread, Activity$ActiviyRecord, Intent), so on.. Why is it throws exception ? What is different between addFooterView and addHeaderView, and how can i add Header to ListActivity ? UPDATE So as you can read in comments, my logcat still doesn't work, but i just tried next at this moment: } catch(Exception e){ Writer result = new StringWriter(); PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter); String error = result.toString(); } and afterward i put breakpoint, and i can read error in expressions section. it said : java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. it was instructive for all of us. After change sort of commands, it works perferctly.

    Read the article

  • ListActivity problem when using with RelativeLayout

    - by tomgamer
    Newb alert, I'm sure I'm doing something dumb here. I've been progressively expanding my UI, and I want to add a ListView in the middle of my UI. When I add it and change the activity to extend a ListActivity instead of just an Activity, I'm getting a Force Close. Using 1.5. Does a ListView not work embedded in a RelativeLayout? Thanks public class Categories extends ListActivity{ final static String[] ITEMS = {"blah", "floop", "gnarlp", "stuff"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.categories); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listrow, R.id.textview, ITEMS); setListAdapter(adapter); XML looks like this: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/ImageView01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="center" android:background="@drawable/background"> </ImageView> <ImageView android:id="@+id/ImageView02" android:src="@drawable/cat_heading" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true"> </ImageView> <ListView android:id="@+id/ListView01" android:layout_below="@id/ImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView> <RelativeLayout android:id="@+id/RelativeLayout02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBottom="@+id/RelativeLayout01" android:layout_centerHorizontal="true"> <ImageButton android:id="@+id/ImageButtonRecipes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:src="@drawable/recipes"></ImageButton> <ImageButton android:id="@+id/ImageButtonSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/ImageButtonRecipes" android:src="@drawable/search"></ImageButton> </RelativeLayout> </RelativeLayout> and the listrow.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview"/> </LinearLayout>

    Read the article

  • ListActivity Item with remote image

    - by TPan
    Hello, I have a ListActivity that should display quite a lot of items and where each list item should contain a text and and an image. The images are gotten from a remote server. How can I display the remote image on the list item. Thanks in advance

    Read the article

  • Android: onListItemClick not getting called in ListActivity

    - by user521469
    I'm having problems with my first Android app. I have subclassed ListActivity, and I'm having no luck getting the overridden onListItemClick() to respond to click events. I've read focus can be a problem, but changing focus in the XML files does not seem to work. Here's the relevant bits of code. Anyone see what's I've buggered up? public class Notepadv1 extends ListActivity { private int mNoteNumber = 1; private NotesDbAdapter mDbHelper; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notepad_list); mDbHelper = new NotesDbAdapter(this); mDbHelper.open(); fillData(); } private void fillData() { // Get all of the notes from the database and create the item list Cursor c = mDbHelper.fetchAllNotes(); startManagingCursor(c); String[] from = new String[] { NotesDbAdapter.KEY_TITLE }; int[] to = new int[] { R.id.text1 }; SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); setListAdapter(notes); } @Override public void onListItemClick (ListView l, View v, int position, long id){ super.onListItemClick(l, v, position, id); AlertDialog alert = new AlertDialog.Builder(this).create(); String message = "row clicked!"; alert.setMessage(message); alert.show(); } notepad_list.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:dividerHeight="6dp"/> <TextView android:id="@android:id/empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_notes" /> </LinearLayout> And notes_row.xml <?xml version="1.0" encoding="utf-8"?> <TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="60dp" android:focusable="false"/>

    Read the article

  • Android: failed to setContentView when switching to ListActivity

    - by Yang
    This is an follow-up issue on my previous question http://stackoverflow.com/questions/2548304/android-which-view-should-i-use-for-showing-text-and-image I read the article about creating ListView for LinearLayout. However, my following code failed at the setContentView() function when I changed "extends Activity" to "extends ListActivity", any idea why? private TextView mSelection; //private ImageView mImages; static final String[] keywords = new String[]{"China", "Japan", "USA", "Canada"}; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contactLayout); mSelection = (TextView)findViewById(R.id.ContactNames); ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.contactlayout, R.id.ContactNames,keywords); setListAdapter(adapter); } My Layout is from this article: http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="6dip" android:src="@drawable/icon" /> <LinearLayout android:orientation="vertical" android:layout_width="0dip" android:layout_weight="1" android:layout_height="fill_parent"> <TextView android:id="@+id/ContactNames" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center_vertical" android:text="My Application" /> <TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:singleLine="true" android:ellipsize="marquee" android:text="Simple application that shows how to use RelativeLayout" /> </LinearLayout>

    Read the article

  • Start TabActivity from ListActivity (which is content of parent TabActivity) in Android

    - by barmaleikin
    Hi guys, I have problems with switching between activities. I have two TabActivities (A and B), each of of tab activity has 4 tabs with ListActivity. I am trying to show B activity onListItemClick. Code on click is: Intent intent = new Intent(getApplicationContext(), TabBActivity.class); startActivity(intent); My manifest file is following: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".SplashScreen" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TabAActivity"> <intent-filter> <action android:name="com.TabAActivity" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TabAListActivityA" android:label="AA"/> <activity android:name=".TabAListActivityB" android:label="AB"/> <activity android:name=".TabAListActivityC" android:label="AC"/> <activity android:name=".TabBActivity" android:label="B"/> <activity android:name=".TabAListBctivityA" android:label="BA"/> <activity android:name=".TabAListBctivityB" android:label="BB"/> <activity android:name=".TabAListBctivityC" android:label="BC"/> </application> </manifest> Is my manifest correct or maybe something is wrong with code? I would appreciate any help on this topic.

    Read the article

  • Android ListActivity with Bitmaps and Garbage Collection issue

    - by chis54
    I have a ListActivity and in it I set my list items with a class that extends SimpleCursorAdapter. I'm overriding bindView to set my Views. I have some TextViews and ImageViews. This is how I set my list items in my cursor adapter: String variableName = "drawable/q" + num + "_200px"; int imageResource = context.getResources().getIdentifier(variableName, "drawable", context.getPackageName()); if (imageResource != 0 ) { // The drawable exists Bitmap b = BitmapFactory.decodeResource(context.getResources(), imageResource); width = b.getWidth(); height = b.getHeight(); imageView.getLayoutParams().width = (int) (width); imageView.getLayoutParams().height = (int) (height); imageView.setImageResource(imageResource); } else { imageView.setImageResource(R.drawable.25trans_200px); } The problem I'm having is whenever I update my list with setListAdapter I get a large amount of garbage collection: D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 125K, 51% free 2710K/5447K, external 2022K/2137K, paused 75ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 30K, 51% free 2701K/5447K, external 2669K/2972K, paused 64ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 23K, 51% free 2713K/5447K, external 3479K/3579K, paused 53ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 22K, 51% free 2706K/5447K, external 3303K/3352K, paused 64ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 21K, 51% free 2722K/5447K, external 3569K/3685K, paused 102ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 23K, 50% free 2755K/5447K, external 3499K/3605K, paused 65ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 23K, 50% free 2771K/5447K, external 4213K/4488K, paused 53ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 18K, 49% free 2796K/5447K, external 5057K/5343K, paused 75ms D/dalvikvm(18637): GC_EXTERNAL_ALLOC freed 28K, 49% free 2803K/5447K, external 5944K/5976K, paused 53ms D/dalvikvm( 435): GC_EXPLICIT freed 6K, 54% free 2544K/5511K, external 1625K/2137K, paused 50ms D/dalvikvm( 165): GC_EXPLICIT freed 85K, 52% free 2946K/6087K, external 4838K/5980K, paused 111ms D/dalvikvm( 448): GC_EXPLICIT freed 1K, 54% free 2540K/5511K, external 1625K/2137K, paused 50ms D/dalvikvm( 294): GC_EXPLICIT freed 8K, 55% free 2598K/5703K, external 1625K/2137K, paused 64ms What can I do to avoid this? It's causing my UI to be sluggish and when I scroll, too.

    Read the article

  • NullPointerException when Using requestWindowFeature(Window.FEATURE_NO_TITLE) on ListActivity Extending Activity

    - by ColorWP.com
    I have a ListActivity extending class and I am trying to hide the default TitleBar (I think it's called ActionBar) using the code below. It works on a regular activity, but not on the ListActivity. How do I accomplish the same in this scenario? public class MyClass extends ListActivity{ @Override public void onCreate(Bundle b) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(b); // Tried Window.FEATURE_NO_TITLE here as well setContentView(R.layout.activity_myclass); getActionBar().setDisplayHomeAsUpEnabled(true); } }

    Read the article

  • how to update an Android ListActivity on changing data of the connected SimpleCursorAdapter

    - by 4485670
    I have the following code. What I want to achieve is to update the shown list when I click an entry so I can traverse through the list. I found the two uncommented ways to do it here on stackoverflow, but neither works. I also got the advice to create a new ListActivity on the data update, but that sounds like wasting resources? EDIT: I found the solution myself. All you need to do is call "SimpleCursorAdapter.changeCursor(new Cursor);". No notifying, no things in UI-Thread or whatever. import android.app.ListActivity; import android.database.Cursor; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ListView; import android.widget.SimpleCursorAdapter; public class MyActivity extends ListActivity { private DepartmentDbAdapter mDbHelper; private Cursor cursor; private String[] from = new String[] { DepartmentDbAdapter.KEY_NAME }; private int[] to = new int[] { R.id.text1 }; private SimpleCursorAdapter notes; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.departments_list); mDbHelper = new DepartmentDbAdapter(this); mDbHelper.open(); // Get all of the departments from the database and create the item list cursor = mDbHelper.fetchSubItemByParentId(1); this.startManagingCursor(cursor); // Now create an array adapter and set it to display using our row notes = new SimpleCursorAdapter(this, R.layout.department_row, cursor, from, to); this.setListAdapter(notes); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // get new data and update the list this.updateData(safeLongToInt(id)); } /** * update data for the list * * @param int departmentId id of the parent department */ private void updateData(int departmentId) { // close the old one, get a new one cursor.close(); cursor = mDbHelper.fetchSubItemByParentId(departmentId); // change the cursor of the adapter to the new one notes.changeCursor(cursor); } /** * safely convert long to in to save memory * * @param long l the long variable * * @return integer */ public static int safeLongToInt(long l) { if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw new IllegalArgumentException (l + " cannot be cast to int without changing its value."); } return (int) l; } }

    Read the article

  • passing data from an activity to an listactivity or listview

    - by wicked14
    need help on passing data from an activity to an listactivity or listview for an android app. im having problems on passing data to a listview. what the app do is from addact class the user can input things to do and in the viewact class this will display the activies add by the user in listview public class addact extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.newact); Button btn1 = (Button)findViewById(R.id.btnsave); final EditText et1 = (EditText)findViewById(R.id.etactivity); btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent it = new Intent(addact.this, viewact.class); it.putExtra("thekey", et1.getText().toString()); startActivity(it); } }); } } public class viewact extends ListActivity { String addToDo =getIntent().getExtras().getString("thekey"); String[] toDoAct = new String[] {addToDo }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.viewact); setListAdapter(new ArrayAdapter<String>(this, R.layout.viewact,toDoAct)); ListView listView = getListView(); listView.setTextFilterEnabled(true); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { for (int i=0; i < 2; i++) { Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_LONG).show(); } } }); } }

    Read the article

  • OnFinishInflate inside ListActivity

    - by zegnus
    I have a main class filled with a cursor adapter: public class MainMenu extends ListActivity{ ... private void updateData(){ ... SimpleAdapter notes = new SimpleAdapter(this, array, R.layout.row_task, from, to); setListAdapter(notes); } } I need to know when this list has finnished to inflate it, so I've discovered this methods: ListView.onFinishInflate()... But I have no idea how to override it inside my code. Any idea?

    Read the article

  • Using listactivity view to create table in android

    - by cppdev
    I'm pretty new to android. I want to create a table in my Wapplication that will have three columns. Once column would have string, another would have a image and last column would have a integer. Again, I want to have table rows selectable. Can this be achieved by extending ListActivity ? What is the best to way to create such a table in android ?

    Read the article

  • Passing data between android ListActivities in Java

    - by Will Janes
    I am new to Android! I am having a problem getting this code to work... Basically I Go from one list activity to another and pass the text from a list item through the intent of the activity to the new list view, then retrieve that text in the new list activity and then preform a http request based on value of that list item. Log Cat 04-05 17:47:32.370: E/AndroidRuntime(30135): FATAL EXCEPTION: main 04-05 17:47:32.370: E/AndroidRuntime(30135): java.lang.ClassCastException:android.widget.LinearLayout 04-05 17:47:32.370: E/AndroidRuntime(30135): at com.thickcrustdesigns.ufood.CatogPage$1.onItemClick(CatogPage.java:66) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.widget.ListView.performItemClick(ListView.java:3731) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1959) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.os.Handler.handleCallback(Handler.java:587) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.os.Handler.dispatchMessage(Handler.java:92) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.os.Looper.loop(Looper.java:130) 04-05 17:47:32.370: E/AndroidRuntime(30135): at android.app.ActivityThread.main(ActivityThread.java:3691) 04-05 17:47:32.370: E/AndroidRuntime(30135): at java.lang.reflect.Method.invokeNative(Native Method) 04-05 17:47:32.370: E/AndroidRuntime(30135): at java.lang.reflect.Method.invoke(Method.java:507) 04-05 17:47:32.370: E/AndroidRuntime(30135): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 04-05 17:47:32.370: E/AndroidRuntime(30135): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 04-05 17:47:32.370: E/AndroidRuntime(30135): at dalvik.system.NativeStart.main(Native Method) ListActivity 1 package com.thickcrustdesigns.ufood; import java.util.ArrayList; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; public class CatogPage extends ListActivity { ListView listView1; Button btn_bk; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.definition_main); btn_bk = (Button) findViewById(R.id.btn_bk); listView1 = (ListView) findViewById(android.R.id.list); ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("request", "categories")); ArrayList<JSONObject> jsondefs = Request.fetchData(this, nvp); String[] defs = new String[jsondefs.size()]; for (int i = 0; i < jsondefs.size(); i++) { try { defs[i] = jsondefs.get(i).getString("Name"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } uFoodAdapter adapter = new uFoodAdapter(this, R.layout.definition_list, defs); listView1.setAdapter(adapter); ListView lv = getListView(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView tv = (TextView) view; String p = tv.getText().toString(); Intent i = new Intent(getApplicationContext(), Results.class); i.putExtra("category", p); startActivity(i); } }); btn_bk.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { Intent i = new Intent(getApplicationContext(), UFoodAppActivity.class); startActivity(i); } }); } } **ListActivity 2** package com.thickcrustdesigns.ufood; import java.util.ArrayList; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.os.Bundle; import android.widget.ListView; public class Results extends ListActivity { ListView listView1; enum Category { Chicken, Beef, Chinese, Cocktails, Curry, Deserts, Fish, ForOne { public String toString() { return "For One"; } }, Lamb, LightBites { public String toString() { return "Light Bites"; } }, Pasta, Pork, Vegetarian } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.definition_main); listView1 = (ListView) findViewById(android.R.id.list); Bundle data = getIntent().getExtras(); String category = data.getString("category"); Category cat = Category.valueOf(category); String value = null; switch (cat) { case Chicken: value = "Chicken"; break; case Beef: value = "Beef"; break; case Chinese: value = "Chinese"; break; case Cocktails: value = "Cocktails"; break; case Curry: value = "Curry"; break; case Deserts: value = "Deserts"; break; case Fish: value = "Fish"; break; case ForOne: value = "ForOne"; break; case Lamb: value = "Lamb"; break; case LightBites: value = "LightBites"; break; case Pasta: value = "Pasta"; break; case Pork: value = "Pork"; break; case Vegetarian: value = "Vegetarian"; } ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("request", "category")); nvp.add(new BasicNameValuePair("cat", value)); ArrayList<JSONObject> jsondefs = Request.fetchData(this, nvp); String[] defs = new String[jsondefs.size()]; for (int i = 0; i < jsondefs.size(); i++) { try { defs[i] = jsondefs.get(i).getString("Name"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } uFoodAdapter adapter = new uFoodAdapter(this, R.layout.definition_list, defs); listView1.setAdapter(adapter); } } Request package com.thickcrustdesigns.ufood; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONObject; import android.content.Context; import android.util.Log; import android.widget.Toast; public class Request { @SuppressWarnings("null") public static ArrayList<JSONObject> fetchData(Context context, ArrayList<NameValuePair> nvp) { ArrayList<JSONObject> listItems = new ArrayList<JSONObject>(); InputStream is = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://co350-11d.projects02.glos.ac.uk/php/database.php"); httppost.setEntity(new UrlEncodedFormEntity(nvp)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection" + e.toString()); } // convert response to string String result = ""; try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); InputStream stream = null; StringBuilder sb = null; while ((result = reader.readLine()) != null) { sb.append(result + "\n"); } stream.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } try { JSONArray jArray = new JSONArray(result); for (int i = 0; i < jArray.length(); i++) { JSONObject jo = jArray.getJSONObject(i); listItems.add(jo); } } catch (Exception e) { Toast.makeText(context.getApplicationContext(), "None Found!", Toast.LENGTH_LONG).show(); } return listItems; } } Any help would be grateful! Many Thanks EDIT Sorry very tired so missed out my 2nd ListActivity package com.thickcrustdesigns.ufood; import java.util.ArrayList; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.os.Bundle; import android.widget.ListView; public class Results extends ListActivity { ListView listView1; enum Category { Chicken, Beef, Chinese, Cocktails, Curry, Deserts, Fish, ForOne { public String toString() { return "For One"; } }, Lamb, LightBites { public String toString() { return "Light Bites"; } }, Pasta, Pork, Vegetarian } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.definition_main); listView1 = (ListView) findViewById(android.R.id.list); Bundle data = getIntent().getExtras(); String category = data.getString("category"); Category cat = Category.valueOf(category); String value = null; switch (cat) { case Chicken: value = "Chicken"; break; case Beef: value = "Beef"; break; case Chinese: value = "Chinese"; break; case Cocktails: value = "Cocktails"; break; case Curry: value = "Curry"; break; case Deserts: value = "Deserts"; break; case Fish: value = "Fish"; break; case ForOne: value = "ForOne"; break; case Lamb: value = "Lamb"; break; case LightBites: value = "LightBites"; break; case Pasta: value = "Pasta"; break; case Pork: value = "Pork"; break; case Vegetarian: value = "Vegetarian"; } ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("request", "category")); nvp.add(new BasicNameValuePair("cat", value)); ArrayList<JSONObject> jsondefs = Request.fetchData(this, nvp); String[] defs = new String[jsondefs.size()]; for (int i = 0; i < jsondefs.size(); i++) { try { defs[i] = jsondefs.get(i).getString("Name"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } uFoodAdapter adapter = new uFoodAdapter(this, R.layout.definition_list, defs); listView1.setAdapter(adapter); } } Sorry again! Cheers guys!

    Read the article

  • Custom Item in ListActivity on Android

    - by Honza Pokorny
    Hello everyone, I've spent hours reading through the SDK reference, googling and reading tutorials - but I still can't figure it out. I would like to know how to create a custom list item in the ListActivity widget on Android. Something similar to a Twitter client interface. Each list item has different types of text, possibly an icon, etc. Does anyone know of any resources that would help me understand the process of creating something like that? Any guidance would be appreciated. Thanks

    Read the article

  • How to add Listview in tab activity?

    - by sandip armal
    I have one "SubjectTabActivity" and i need to show listview on this activity. But when i want to implement ListActivity it doesn't show listActivity. I have two(addchapter,addsubject) xml file with "SubjectTabActivity". and i need to show my database item il list view in respective xml file. but i don't understand how to do that? How to add Listactivity in TabActivity?. Please give me any reference or code. Thanks in advance.. Here is my reference code. public class MasterMainActivity extends TabActivity { LayoutInflater layoutInflater = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.master); Intent intent=getIntent(); setResult(RESULT_OK, intent); layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); TabHost tabHost = getTabHost(); TabHost.TabSpec tab1spec = tabHost.newTabSpec("tabOneSpec"); ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.subject); tab1spec.setIndicator("Subject", imgView.getBackground()); tab1spec.setContent(new TabContentLayout()); TabHost.TabSpec tab2spec = tabHost.newTabSpec("tabTwoSpec"); tab2spec.setContent(new TabContentLayout()); ImageView imgView1 = new ImageView(this); imgView1.setBackgroundResource(R.drawable.chapter); tab2spec.setIndicator("Chapter", imgView1.getBackground()); tabHost.addTab(tab1spec); tabHost.addTab(tab2spec); } private class TabContentLayout implements TabHost.TabContentFactory { @Override public View createTabContent(String tag) { View view = null; if(tag.equals("tabOneSpec")) { try { //static final String[] FRUITS = new String[] { "Apple", "Avocado", "Banana", // "Blueberry", "Coconut", "Durian", "Guava", "Kiwifruit", //"Jackfruit", "Mango", "Olive", "Pear", "Sugar-apple" }; view = (LinearLayout) layoutInflater.inflate(R.layout.subjecttabview, null); //setListAdapter(new ArrayAdapter<String>(this, R.layout.subjecttabview,FRUITS)); } catch(Exception e) { e.printStackTrace(); } } if(tag.equals("tabTwoSpec")) { try { view = (LinearLayout) layoutInflater.inflate(R.layout.chaptertabview, null); } catch(Exception e) { e.printStackTrace(); } } return view; } } How to add ListActivity in this TabActivity

    Read the article

  • Problem using setEmptyView on a ListActivity

    - by Pentium10
    I have the following setup, and the empty view text doesn't show up... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getListView().setEmptyView(findViewById(R.id.empty)); getListView().setTextFilterEnabled(true); setListAdapter(null);// to have empty list } The layout file is: <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/myScrollLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <FrameLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="false" /> <!-- Here is the view to show if the list is emtpy --> <ScrollView android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/emptyText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/contact_empty_help" android:textSize="20sp" android:textColor="?android:attr/textColorSecondary" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="10dip" android:lineSpacingMultiplier="0.92" /> </ScrollView> </FrameLayout> </LinearLayout> String is defined as: <string name="contact_empty_help">"You don't have any contacts to display.\n\nTo add contacts, you have to:\n \n<li><font fgcolor="#ffffffff">Go to <b>Contacts</b></font> application to create new contacts\n</li> \n<li><font fgcolor="#ffffffff"><b>Import from VCF file</b></font>, this is available in Contacts menu, the file most be on the root of the SD card\n</li>" </string> Since the list is empty, it should show me the text defined. I followed the example from the List8 http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List8.html http://developer.android.com/intl/de/resources/samples/ApiDemos/res/layout/list_8.xml

    Read the article

  • Why is my onSharedPreferenceChangeListener being called multiple times when I change a pref.

    - by brockoli
    I've written an app with 3 tabs. Each tab has the same list view with different data sources. I have setup SharedPreferences in the tabhost activity, but I put my onSharedPreferenceChangeListener method in my listactivity. When I change a preference, my listener gets called and it updates my database. This is all working. However, if I change the data in tab 1, it calls my listener once. If I change the data for tab 2 it calls it twice and if I change the data in tab 3 it calls it three times. Any idea why it works this way? I guess I could setup my shared prefs in my listactivity and that might avoid the issue, but I'm curious why my listener is called multiple times if it's in a different tab. brockoli

    Read the article

  • java.lang.IllegalStateException: The content of the adapter has changed but ListView.... inspite of calling notifydatasetchanged()

    - by Mistaken
    What are the best practices to be followed to update the contents of a listactivty by a background thread (Async Task) ? 1) Am calling the notifyDataSetChanged() to update the adapter as soon as i manipulate the contents of the adapter but still my app force closes while the user scrolls or click on the list. Any pointers to prevent this would be very helpfull. Logcat: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. 2) Where exaclty should i update contents of the listactivity ? inside the doInBackground() or onProgressUpdate()? 3) Am experiencing regular crashes when the user clicks the list item. So will disabling click events on the listactivty during the background operation solve the problem ? If so am not sure how to remove or set item click listeners dynamically to the listactivity. Please instruct me on the too. 4) I dont think blocking all ui interactions during the background async task execution is the only way to solve the problem. I know there is a simple way of doing this but need some help. Thanks in advance. This is my onCreate... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fa); tvStatus=(TextView) findViewById(R.id.tvStatus); adapter = new SimpleAdapter( this, mostPopularList, R.layout.list_item, new String[] {"title","author","views","date"}, new int[] {R.id.textView1,R.id.textView2,R.id.textView4,R.id.textView3}); //populateList(); setListAdapter(adapter); } My async task... private class LongOperation extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { // code for adding new listactivty items } @Override protected void onPostExecute(String networkStatus) { adapter.notifyDataSetChanged(); } @Override protected void onPreExecute() { } @Override protected void onProgressUpdate(Void... values) { } }

    Read the article

  • Entering and retrieving data from SQLite for an android List View

    - by Infiniti Fizz
    Hi all, I started learning android development a few weeks ago and have gone through the developer.android.com tutorials etc. But now I have a problem. I'm trying to create an app which tracks the usage of each installed app. Therefore I'm pulling the names of all installed apps using the PackageManager and then trying to put them into an SQLite database table. I am using the Notepad Tutorial SQLite implementation but I'm running into some problems that I have tried for days to solve. I have 2 classes, the DBHelper class and the actual ListActivity class. For some reason the app force closes when I try and run my fillDatabase() function which gets all the app names from the PackageManager and tries to put them into the database: private void fillDatabase() { PackageManager manager = this.getPackageManager(); List<ApplicationInfo> appList = manager.getInstalledApplications(0); for(int i = 0; i < appList.size(); i++) { mDbHelper.addApp(manager.getApplicationLabel(appList.get(i)).toString(), 0); } } addApp() is a function defined in my AppsDbHelper class and looks as follows: public long createApp(String name, int usage) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_NAME, name); initialValues.put(KEY_USAGE, usage); return mDb.insert(DATABASE_TABLE, null, initialValues); } The database create is defined as follows: private static final String DATABASE_CREATE = "create table notes (_id integer primary key autoincrement, " + "title text not null, usage integer not null);"; I have commented out all statements that follow fillDatabase(); in the onCreate() method of the ListActivity and so know that it is definetely the problem but I don't know why. I am taking the appName and putting it into the KEY_NAME field of the row and putting 0 into the KEY_USAGE field of the row (because initially, my app will default the usage of each app to 0 (not used yet)). If my addApp() function doesn't take the usage and just puts KEY_NAME into the ContentValues and into the database, it seems to work fine, but I want a column for usage. Any ideas why it is not working? Have I overlooked something? Thanks for your time, InfinitiFizz

    Read the article

1 2 3 4 5 6  | Next Page >