Search Results

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

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

  • How do I get my ActivityUnitTestCases to sync with the MessageQueue thread and call my Handler?

    - by Ricardo Gladwell
    I'm writing unit tests for a ListActivity in Android that uses a handler to update a ListAdapter. While my activity works in the Android emulator, running the same code in a unit test doesn't update my adapter: calls to sendEmptyMessage do not call handleMessage in my activity's Handler. How do I get my ActivityUnitTestCase to sync with the MessageQueue thread and call my Handler? The code for the Activity is somewhat like this: public class SampleActivity extends ListActivity implements SampleListener { List samples = new ArrayList(); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample_list); listView.setEmptyView(findViewById(R.id.empty)); } private final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { // unit test never reaches here sharesAdapter = new SampleAdapter(SampleActivity.this, samples); setListAdapter(sharesAdapter); } }; public void handleSampleUpdate(SampleEvent event) { samples.add(event.getSample()); handler.sendEmptyMessage(0); } } The code for my unit test is somewhat like this: public class SampleActivityTest extends ActivityUnitTestCase<SampleActivity> { public SampleActivityTest() { super(SampleActivity.class); } @MediumTest public void test() throws Exception { final SampleActivity activity = startActivity(new Intent(Intent.ACTION_MAIN), null, null); final ListView listView = (ListView) activity.findViewById(android.R.id.list); activity.handleSampleUpdate(new SampleEvent(this)); // unit test assert fails on this line: assertTrue(listView.getCount() == 1); } }

    Read the article

  • Android Loading listview items from service results in hang

    - by Isaac Waller
    Hello, In my Android application, I have a ListActivity. This ListActivity uses a SimpleAdapter that I fill with items from my service. So, in my code, I do: MySuperCoolService.Binder serviceBinder = null; private ServiceConnection serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "Service connection: connected!"); serviceBinder = (MySuperCoolService.Binder)service; } public void onServiceDisconnected(ComponentName className) { Log.d(TAG, "Service connection: disconnected"); serviceBinder = null; } }; bindService(new Intent(this, MySuperCoolService.class), serviceConnection, BIND_AUTO_CREATE); while(serviceBinder==null) { Thread.Sleep(1000); } // now retrieve from service using binder and set list adapter This whole operation takes hardly any time (less than a second), so I want it to run in the UI thread. See my onCreate: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); fillDataUsingCodeAbove(); } The reason I want this to run in the UI thread is that if you have a list item selected, or you have scrolled to a certain position in the ListView, and you rotate the device or take out the keyboard or something (to trigger a configuration change) when my activity is restarted, Android will try to restore the state right after onCreate. But, if I run it in a separate thread, it will not. Also there is a cool fadein animation too :) The problem I am having with running it in the UI thread is that when I try to bind to the service, that service bind request gets put onto the message queue. But then when I go into my loop, I stop the message queue from looping. So my program hangs, because it's waiting for the service to get bound, and the service won't get bound until the loop ends. I have thought of putting Looper.loop() inside my loop, but that just hangs it at Looper.loop() (I don't know why.) Sorry for such a long question, Isaac Waller

    Read the article

  • How to call Android contacts list?

    - by aZn137
    Hi, I'm making an Android app, and need to call the phone's contact list. I need to call the contacts list function, pick a contact, then return to my app with the contact's name. Here's the code I got on the internet, but it doesnt work. Please help: import android.app.ListActivity; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.provider.Contacts.People; import android.view.View; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.TextView; public class Contacts extends ListActivity { private ListAdapter mAdapter; public TextView pbContact; public static String PBCONTACT; public static final int ACTIVITY_EDIT=1; private static final int ACTIVITY_CREATE=0; // Called when the activity is first created. @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Cursor C = getContentResolver().query(People.CONTENT_URI, null, null, null, null); startManagingCursor(C); String[] columns = new String[] {People.NAME}; int[] names = new int[] {R.id.row_entry}; mAdapter = new SimpleCursorAdapter(this, R.layout.mycontacts, C, columns, names); setListAdapter(mAdapter); } // end onCreate() // Called when contact is pressed @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Cursor C = (Cursor) mAdapter.getItem(position); PBCONTACT = C.getString(C.getColumnIndex(People.NAME)); // RHS 05/06 //pbContact = (TextView) findViewById(R.id.myContact); //pbContact.setText(new StringBuilder().append("b")); Intent i = new Intent(this, NoteEdit.class); startActivityForResult(i, ACTIVITY_CREATE); } }

    Read the article

  • Error Message-The source attachment does not contain the source for the file ListView.class

    - by user603695
    Hello, new to Android. I get the following message in the debugger perspective: The source attachment does not contain the source for the file ListView.class You can change the source attachment by clicking the change attached Source Below Needless to say the app errors. I've tried to change the source attachment to the location path: C:/Program Files/Android/android-sdk-windows/platforms/android-8/android.jar However, this did not work. Any thoughts would be much appreciated. Code is: import android.app.ListActivity; import android.os.Bundle; import android.view.*; import android.widget.*; public class HelloListView extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter<String>(this, R.layout.main, COUNTRIES)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); } static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania", "Algeria", "American Samoa... Thanks!

    Read the article

  • Android: How to put ListView in XML?

    - by FloIancu
    I want to make a simple app that shows a list of contacts (name, surname). My code: package lista.android; import java.util.*; import android.app.ListActivity; import android.os.Bundle; import android.widget.*; class Contact{ String nume; String prenume; Contact(String nume, String prenume){ this.nume=nume; this.prenume=prenume; } public String toString(){ return prenume +" "+ nume; } } public class Lista1Activity extends ListActivity { /** Called when the activity is first created. */ ArrayList <Contact> lista; ArrayAdapter <Contact> adaptor; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setListAdapter(adaptor); lista=new ArrayList<Contact>(); adaptor=new ArrayAdapter<Contact>(this, R.id.element, lista); adaugaContact("Florian", "Iancu"); adaugaContact("Ioana", "Constantina"); } public void adaugaContact(String nume, String prenume){ lista.add(new Contact(nume, prenume)); adaptor.notifyDataSetChanged(); } } In the XML I have the LinearLayout and a TextView that is the list element. When I run it, the simulator says "Sorry, the application [...] has stopped unexpectedly. Please try again." The LogCat tells me I have to have a ListView whose id is android.R.id.lista. If I create a random ListView field in the XML file and give it the "lista" id, it still doesn't work. How to I call that ListView from XML to match something in my Java code? In other words, I know I'm wrong, but where and how do I fix it?

    Read the article

  • Set List View Size Android

    - by Sandeep
    Hello , I am using List View in my project where i have used a xml file which is used to create the list item.Then i have used it programmatically in my class which is extended by ListActivity. But the problem is i have to add a button in the bottom of screen which is not related to list view but List view covers all the screen. So,is there any way to add button in bottom with list view in android. My Code is :- import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; public class Options extends ListActivity { String[] items; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_RIGHT_ICON); items = getResources().getStringArray(R.array.chantOption_array); setListAdapter(new IconicAdapter()); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setBackgroundResource(R.drawable.ichant_logo); setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.icon_t); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), items[position], Toast.LENGTH_SHORT).show(); if ("Gayatri Mantra".equals(items[position].toString())) { int[] timeintervals = { 23900, 24000 }; // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio) startChantActivity(2, 108, R.drawable.gayatri, R.raw.gayatri, R.drawable.icon_gayatri, "Gayatri Mantra", timeintervals); } if ("Om Mani Padme Hum".equals(items[position].toString())) { int[] timeintervals = { 5500, 8200, 11100, 13900, 34100, 36700, 39500, 42300, 59300, 62000, 64800, 67600, 124600 }; // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio) startChantActivity(2, 108, R.drawable.ommanipadmehum, R.raw.om_mani, R.drawable.icon_padme, "Om Mani Padme Hum", timeintervals); } if ("Sai Ram".equals(items[position].toString())) { // Audio time interval for bead+total time duration of audio int[] timeintervals = { 4800, 7500, 10400, 12600, 15800, 18600, 21600, 24400, 25000 }; // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio) startChantActivity(2, 108, R.drawable.sairam, R.raw.sairam, R.drawable.icon_sairam, "Sai Ram", timeintervals); } if ("Aum".equals(items[position].toString())) { // Audio time interval for bead+total time duration of audio int[] timeintervals = { 12850, 13000 }; // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio) startChantActivity(2, 108, R.drawable.aum, R.raw.aum, R.drawable.ico_aum, "Aum", timeintervals); } } }); } class IconicAdapter extends ArrayAdapter { IconicAdapter() { super(Options.this, R.layout.list_item, items); } public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row = inflater.inflate(R.layout.list_item, parent, false); TextView label = (TextView) row.findViewById(R.id.label); label.setText(" "+items[position]); ImageView icon = (ImageView) row.findViewById(R.id.icon); if (items[position].equals("Gayatri Mantra")) { icon.setImageResource(R.drawable.icon_gayatri); } if (items[position].equals("Om Mani Padme Hum")) { icon.setImageResource(R.drawable.icon_padme); } if (items[position].equals("Sai Ram")) { icon.setImageResource(R.drawable.icon_sairam); } if (items[position].equals("Aum")) { icon.setImageResource(R.drawable.ico_aum); } return (row); } } protected void startChantActivity(int mala_loop, int beads_loop, int background, int media, int titleIcon, String title, int[] timeintervals) { Bundle bundle = new Bundle(); bundle.putInt("mala_loop", mala_loop); bundle.putInt("beads_loop", beads_loop); bundle.putInt("background", background); bundle.putInt("media", media); bundle.putInt("titleIcon", titleIcon); bundle.putString("title", title); bundle.putIntArray("intervals", timeintervals); Intent intent = new Intent(this, ChantBliss.class); intent.putExtras(bundle); startActivityForResult(intent, this.getSelectedItemPosition()); } } And Corresponding xml file is: <?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="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:paddingLeft="2px" android:paddingRight="2px" android:paddingTop="2px" android:layout_height="wrap_content" /> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="22sp" android:textColor="#ff000000" /> </LinearLayout> Thanks in Advance: Sandeep

    Read the article

  • Android ListView setSelection() does not seem to work.

    - by alkar
    I have a ListActivity that implements onListItemClick() and calls a doSomething() function of the class. The latter contains l.setSelection(position) where l is the ListView object. Now there is a onClickListener() listening for a button click that perfoms some actions and that too calls doSomething(). In the first case, the selected item get positioned appropriately, but in the latter, nothing happens. Any clues about this strange behaviour and how I might make it work?

    Read the article

  • Android:How to display images from the in a ListView?

    - by Maxood
    Android:How to display images from the web in a ListView?I have the following code to display image from a URL in an ImageView: import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import android.app.ListActivity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.widget.ImageView; public class HttpImgDownload extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Bitmap bitmap = // DownloadImage( // "http://www.streetcar.org/mim/cable/images/cable-01.jpg"); DownloadImage( "http://s.twimg.com/a/1258674567/images/default_profile_3_normal.png"); ImageView img = (ImageView) findViewById(R.id.img); img.setImageBitmap(bitmap); } private InputStream OpenHttpConnection(String urlString) throws IOException { InputStream in = null; int response = -1; URL url = new URL(urlString); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) throw new IOException("Not an HTTP connection"); try{ HttpURLConnection httpConn = (HttpURLConnection) conn; httpConn.setAllowUserInteraction(false); httpConn.setInstanceFollowRedirects(true); httpConn.setRequestMethod("GET"); httpConn.connect(); response = httpConn.getResponseCode(); if (response == HttpURLConnection.HTTP_OK) { in = httpConn.getInputStream(); } } catch (Exception ex) { throw new IOException("Error connecting"); } return in; } private Bitmap DownloadImage(String URL) { Bitmap bitmap = null; InputStream in = null; try { in = OpenHttpConnection(URL); bitmap = BitmapFactory.decodeStream(in); in.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return bitmap; } } Now how can i display images in an array in a listview? Here's how i want to display the images: http://sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=420&width=279

    Read the article

  • JavaNullPointerException/Layout Error when working with lists and ListView on Android

    - by psyhclo
    Hey, I'm trying to implement a ListView on Android, which will print the data retrieved from the SQLite Database. So I want to retrieve a lot of columns from the table and add this to a list, so I will print this list as a ListView. For this I created a method that will select all the columns from the table in a separate class, and I will print the ListView in a ListActivity. I want to retrieve 6 columns of the table, which is represented by the ids 2, 4, 5, 6, 7, 9. But it shows a lot of errors: 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): FATAL EXCEPTION: main 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): java.lang.NullPointerException 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.AbsListView.obtainView(AbsListView.java:1418) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.makeAndAddView(ListView.java:1745) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.fillDown(ListView.java:670) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.fillFromTop(ListView.java:727) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.layoutChildren(ListView.java:1598) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.AbsListView.onLayout(AbsListView.java:1248) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.os.Handler.dispatchMessage(Handler.java:99) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.os.Looper.loop(Looper.java:123) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.app.ActivityThread.main(ActivityThread.java:3647) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at java.lang.reflect.Method.invokeNative(Native Method) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at java.lang.reflect.Method.invoke(Method.java:507) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at dalvik.system.NativeStart.main(Native Method) Here is the code of the method that select the data. public List<String> selectAll() { List<String> list1 = new ArrayList<String>(); List<String> list2 = new ArrayList<String>(); List<String> list3 = new ArrayList<String>(); List<String> list4 = new ArrayList<String>(); List<String> list5 = new ArrayList<String>(); List<String> list6 = new ArrayList<String>(); Cursor cursor = this.db.query(TABLE_NAME, null, null, null, null, null, "duration desc"); if (cursor.moveToFirst()) { do { list1.add(cursor.getString(2)); list2.add(cursor.getString(4)); list3.add(cursor.getString(5)); list4.add(cursor.getString(6)); list5.add(cursor.getString(7)); list6.add(cursor.getString(9)); list1.addAll(list2); list1.addAll(list3); list1.addAll(list4); list1.addAll(list5); list1.addAll(list6); } while (cursor.moveToNext()); Log.i(TAG, "After cursor.moveToNext()"); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Log.i(TAG, "Before selectAll returnment"); return list1; } And here is the code of the ListActivity class: public class RatedCalls extends ListActivity { private static final String LOG_TAG = "RatedCallsActivity"; private CallDataHelper cdh; StringBuilder sb = new StringBuilder(); OpenHelper openHelper = new OpenHelper(RatedCalls.this); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(LOG_TAG, "calling from onCreate()"); cdh = new CallDataHelper(this); Log.i(LOG_TAG, "--->>> before calling the service"); startService(new Intent(this, RatedCallsService.class)); Log.i(LOG_TAG, "Service called."); Log.i(LOG_TAG, "--->>> after calling the service"); fillList(); } public void fillList() { List<String> ratedCalls = this.cdh.selectAll(); setListAdapter(new ArrayAdapter<String>(this, R.layout.listitem, ratedCalls)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); } }

    Read the article

  • Android - Display HTML Formatted String

    - by Soren
    I need an example of how to display the strings that I have marked up with simple html into a TextView. I have found "Spanned fromHtml(String source)", but I don't know how to plug it into my java code. Here is my Java: package com.SorenWinslow.TriumphHistory; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class TriumphHistory extends ListActivity { String[] HistoryList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayAdapter<String> adapter; HistoryList = getResources().getStringArray(R.array.history); adapter = new ArrayAdapter<String> (this,R.layout.historylistlayout,HistoryList); setListAdapter(adapter); } } Here is a sample of history: <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="history"> <item><b>1883</b><br/>Some stuff happened</item> <item><b>1884</b><br/>Some more stuff happened <i>before</i> the other stuff </item> <resources> Here is my historylistlayout.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:textColor="#ffffff" android:background="#000050" android:layout_marginTop="5px" android:minHeight="?android:attr/listPreferredItemHeight" android:padding="3px" android:textSize="8pt" android:layout_gravity="top|left"/> And here is my main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:textColor="#ffffff" android:background="#000080" android:isScrollContainer="true" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarStyle="insideOverlay"> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:dividerHeight="1px"/> </LinearLayout>

    Read the article

  • Andorid - Display HTML Formatted String

    - by Soren
    I need an example how to display the strings that I have marked up with simple html into a TextView. I have found "Spanned fromHtml(String source)", but I don't know how to plug it into my java code. Here is my Java: package com.SorenWinslow.TriumphHistory; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class TriumphHistory extends ListActivity { String[] HistoryList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayAdapter<String> adapter; HistoryList = getResources().getStringArray(R.array.history); adapter = new ArrayAdapter<String> (this,R.layout.historylistlayout,HistoryList); setListAdapter(adapter); } } Here is a sample of history: <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="history"> <item><b>1883</b><br/>Some stuff happened</item> <item><b>1884</b><br/>Some more stuff happened <i>before</i> the other stuff </item> <resources> Here is my historylistlayout.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:textColor="#ffffff" android:background="#000050" android:layout_marginTop="5px" android:minHeight="?android:attr/listPreferredItemHeight" android:padding="3px" android:textSize="8pt" android:layout_gravity="top|left"/> And here is my main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:textColor="#ffffff" android:background="#000080" android:isScrollContainer="true" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarStyle="insideOverlay"> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:dividerHeight="1px"/> </LinearLayout>

    Read the article

  • changing image on listview at runtime in android

    - by Raj
    Hi, I am using a LinearLayout to display some Text and image. I have the images at drawable/ and i am implimenting this with ListActivity with some onListItemClick functionality. now i wants to change the image for the rows which are processed by onclick functionality to show the status as processed. can some one help me in this issue to change the image at runtime. the following is my implimentation. public class ListWithImage extends ListActivity { /** Called when the activity is first created. */ private SimpleCursorAdapter myAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // raj setContentView(R.layout.main); Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null); startManagingCursor(cursor); String[] columns = new String[] {People.NAME, People.NUMBER}; int[] names = new int[] {R.id.contact_name, R.id.contact_number}; myAdapter = new SimpleCursorAdapter(this, R.layout.main, cursor, columns, names); setListAdapter(myAdapter); } @Override protected void onListItemClick(ListView listView, View view, int position, long id) { super.onListItemClick(listView, view, position, id); Intent intent = new Intent(Intent.ACTION_CALL); Cursor cursor = (Cursor) myAdapter.getItem(position); long phoneId = cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID)); intent.setData(ContentUris.withAppendedId(Phones.CONTENT_URI, phoneId)); startActivity(intent); } } and main.xml is : <LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="250px"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name: " /> <TextView android:id="@+id/contact_name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Phone: " /> <TextView android:id="@+id/contact_number" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>

    Read the article

  • Help with ListView Databse

    - by Weston Dunn
    I am having issues @ run with this code: App Force Closing.. Sprinter.Java import android.app.ListActivity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.ListAdapter; import android.widget.SimpleCursorAdapter; public class Sprinter extends ListActivity { /** Called when the activity is first created. */ final static String MY_DB_NAME = "Sprinter"; final static String MY_DB_TABLE = "Stations"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SQLiteDatabase myDB = null; try { myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null); myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE + "_id integer primary key autoincrement, name varchar(100);"); myDB.execSQL("INSERT INTO " + MY_DB_TABLE + " (_id, name)" + " VALUES ('', 'Oceanside Transit Center');"); myDB.execSQL("INSERT INTO " + MY_DB_TABLE + " (_id, name)" + " VALUES ('', 'Coast Highway');"); Cursor mCursor = myDB.rawQuery("SELECT name" + " FROM " + MY_DB_TABLE, null); startManagingCursor(mCursor); ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_item, mCursor, new String[] { "name" }, new int[] { R.id.Name }); this.setListAdapter(adapter); this.getListView().setTextFilterEnabled(true); } finally { if (myDB != null) { myDB.close(); } } } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ListView> <TextView android:id="@id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="No Data" /> </LinearLayout> list_item.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/Name" android:layout_width="wrap_content" android:layout_height="wrap_content"> </TextView> </LinearLayout>

    Read the article

  • is it possible to create listview inside dialog?

    - by UMMA
    dear friends, i have created a custom dialog class public class NewPost extends Dialog { // functionality } now my requirement is to create listview inside it. i know we can create textboxes,buttons,dropdown list inside it. but in order to create list view we should inherit our class from listActivity class what you suggest is it possible or not if yes then how to achieve this using any interface or what? any help would be appriciated.

    Read the article

  • get Phone numbers from android phone

    - by Luca
    Hi! First of all i'm sorry for my english... I've a problem getting phone numbers from contacts. That's my code import android.app.ListActivity; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract; import android.widget.SimpleAdapter; import android.widget.Toast; import java.util.ArrayList; import java.util.HashMap; public class TestContacts extends ListActivity { private ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); private SimpleAdapter numbers; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contacts); numbers = new SimpleAdapter( this, list, R.layout.main_item_two_line_row, new String[] { "line1","line2" }, new int[] { R.id.text1, R.id.text2 } ); setListAdapter( numbers ); Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { String contactId = cursor.getString(cursor.getColumnIndex( ContactsContract.Contacts._ID)); String hasPhone = cursor.getString(cursor.getColumnIndex( ContactsContract.Contacts.HAS_PHONE_NUMBER)); //check if the contact has a phone number if (Boolean.parseBoolean(hasPhone)) { Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null); while (phones.moveToNext()) { // Get the phone number!? String contactName = phones.getString( phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String phoneNumber = phones.getString( phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER)); Toast.makeText(this, phoneNumber, Toast.LENGTH_LONG).show(); drawContact(contactName, phoneNumber); } phones.close(); } }cursor.close(); } private void drawContact(String name, String number){ HashMap<String,String> item = new HashMap<String,String>(); item.put( "line1",name); item.put( "line2",number); list.add( item ); numbers.notifyDataSetChanged(); } } It'seems that no contact have a phone number (i've added 2 contacts on the emulator and i've tried also on my HTC Desire). The problem is that if (Boolean.parseBoolean(hasPhone)) returns always false.. How can i get correctly phone numbers? I've tried to call drawContact(String name, String number) before the if statement without querying for the phone number, and it worked (it draws two times the name). but on the LinearLayout they are not ordered alphabetically... how can i order alphabetically (similar to the original contacts app)? thank you in advice, Luca

    Read the article

  • Changing tabs in android

    - by Pavel
    Hi guys. Can someone please tell me how to change tab by clicking on element INSIDE the tab? I already tried it with global data. The code looks like this: public class Tabs extends TabActivity { int tabNumber = 0; private TabHost tabHost; int returnedTabNumber = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, Tribocracy.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("map").setIndicator("Map", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, Areas.class); spec = tabHost.newTabSpec("areas").setIndicator("Areas", res.getDrawable(R.drawable.ic_tab_albums)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, Settings.class); spec = tabHost.newTabSpec("settings").setIndicator("Settings", res.getDrawable(R.drawable.ic_tab_albums)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(tabNumber); } protected void onResume() { super.onResume(); GlobalData globalData = ((GlobalData)getApplicationContext()); returnedTabNumber = globalData.getTabNumber(); tabHost.setCurrentTab(returnedTabNumber); } } The global adapter looks like this: public class GlobalData extends Application { //---------------------------------------------------- private int Point1; //define the vars here private int Point2; //define the vars here private int Point3; //define the vars here private int Point4; //define the vars here private int Point5; //define the vars here private int Point6; //define the vars here private int tabNumber; public int getTabNumber() //getter of the value { return tabNumber; } public int setTabNumber(int number) //setter of the value { tabNumber = number; return tabNumber; } } Now when I'm trying to change tab in my ListActivity tab by clicking on one of the items it doesn't do anything and stays on the ListActivity tab. Perhaps I shouldn't use onResume() here. Basically I want to go to first tab when I click on one of the items in the list. Please help!

    Read the article

  • android : customer List Adatper + ArrayList

    - by Ram
    Team, Could you please help me debug the issue? ActivityAdapter activityAdapter = new ActivityAdapter(this,activityList); Log.d("list", "List Display - 1"); setListAdapter( activityAdapter ); Log.d("List", "list done"); It's throwing exception at the time of setListAdapter, 05-01 16:59:15.996: WARN/dalvikvm(251): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 05-01 16:59:15.996: ERROR/AndroidRuntime(251): Uncaught handler: thread main exiting due to uncaught exception 05-01 16:59:16.204: ERROR/AndroidRuntime(251): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.antennasoftware.xml/com.antennasoftware.xml.XMLParsing}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.os.Handler.dispatchMessage(Handler.java:99) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.os.Looper.loop(Looper.java:123) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ActivityThread.main(ActivityThread.java:4310) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at java.lang.reflect.Method.invokeNative(Native Method) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at java.lang.reflect.Method.invoke(Method.java:521) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at dalvik.system.NativeStart.main(Native Method) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ListActivity.onContentChanged(ListActivity.java:236) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.Activity.setContentView(Activity.java:1622) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at com.antennasoftware.xml.XMLParsing.onCreate(XMLParsing.java:36) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417) 05-01 16:59:16.204: ERROR/AndroidRuntime(251): ... 11 more Thanks in advance

    Read the article

  • Adding multiple views to a listview.

    - by hwrdprkns
    Hey guys, I tried to add these views to list view using this kind of factory but everytime I try and add the view to a ListActivity, it comes up with nothing. What am I doing wrong? I set my list views like so: List<View> views = new ArrayList<View>(); for(int x =0;x<tagg_views.size();x++) { lv.addHeaderView(views.get(x)); }

    Read the article

  • How to add ListView to MapView from the xml resource ?

    - by user164589
    Hi guys. How to add ListView to MapView from the xml resource ? In order words, I am trying to make a screen contains google MapView and ListView. Because impossible to extends 2 Activitys' (ListActivity & MapActvity), I am trying to add a ListView(It is created from xml resource) to MapView. Thanks in advance.

    Read the article

  • How to implement context menu on key press instead of long click/tap

    - by takyon
    I have a ListActivity and I want to implement context menu for each of the list elements. I know that the common way to do this is to show the context menu on long click/tap. I want to know if there is a way to show the context menu for each element on a key press(preferably the menu key). To rephrase my question, how can I trigger the context menu and not the options menu by pressing the menu key(or any other key).

    Read the article

  • Android : Connecting to MySQL using PHP

    - by user1771128
    I followed the following article http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/ I am able to execute my php file. I executed it individually and its working fine. The problem is in the android execution part. Am posting the Log Cat for the error am facing. Tried putting in a List View with id "list" but the error stil 10-28 16:08:27.201: E/AndroidRuntime(664): **FATAL EXCEPTION: main** 10-28 16:08:27.201: E/AndroidRuntime(664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.city/com.example.city.City}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ActivityThread.access$600(ActivityThread.java:123) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.os.Handler.dispatchMessage(Handler.java:99) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.os.Looper.loop(Looper.java:137) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ActivityThread.main(ActivityThread.java:4424) 10-28 16:08:27.201: E/AndroidRuntime(664): at java.lang.reflect.Method.invokeNative(Native Method) 10-28 16:08:27.201: E/AndroidRuntime(664): at java.lang.reflect.Method.invoke(Method.java:511) 10-28 16:08:27.201: E/AndroidRuntime(664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 10-28 16:08:27.201: E/AndroidRuntime(664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 10-28 16:08:27.201: E/AndroidRuntime(664): at dalvik.system.NativeStart.main(Native Method) 10-28 16:08:27.201: E/AndroidRuntime(664): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ListActivity.onContentChanged(ListActivity.java:243) 10-28 16:08:27.201: E/AndroidRuntime(664): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.Activity.setContentView(Activity.java:1835) 10-28 16:08:27.201: E/AndroidRuntime(664): at com.example.city.City.onCreate(City.java:35) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.Activity.performCreate(Activity.java:4465) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 10-28 16:08:27.201: E/AndroidRuntime(664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 10-28 16:08:27.201: E/AndroidRuntime(664): ... 11 more

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >