ListActivity

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

ListActivity

Postby rajeshcit » Wed Nov 18, 2009 9:52 am

hai,

am new in android application development,am just creating one LISTVIEW with 5 options.selecting any option new activity will show,switching from listactivity to any activity is not working.Listitems shows there.

program is given below,please help me

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListDemo extends ListActivity {
/** Called when the activity is first created. */
private int selectedItem = -1;
protected static final int SUB_ACTIVTY_REQUEST_CODE = 1314;
private String[] country={"China", "America", "Japan", "Russia", "Canada"};

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.listdemo);

//Bind list item to ListView
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, country));
// getListView().setOnClickListener(this);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
//record the selected item
selectedItem = position;

//add passing data
Intent intent = new Intent(ListDemo.this, Editor.class);
//Bundle b = new Bundle();
//b.putString("COUNTRY", country[selectedItem]);
//intent.putExtras(b);
startActivity(intent);
//start editor activity
//super.startSubActivity(intent, SUB_ACTIVTY_REQUEST_CODE);
}


}

Can i use INTENT in listactivity ,intent is work in Activity class,please help me




thanks & regards rajesh
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Top

Postby qlimax » Wed Nov 18, 2009 11:24 am

sure you can.
have you added the new activity to the manifest file?

<activity android:name=".Editor" android:label="@string/app_name" />

if is not that, can you post the logcat error?

bye :arrow:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

ListActivity

Postby rajeshcit » Wed Nov 18, 2009 12:45 pm

hai

yes there is one entry for class EDITOR in androidmainfest.xml like this

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ListDemo"
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=".Editor" android:label="@string/app_name">
</activity>
</application>

how can i get logcat error? am using eclipse ide with android 1.5 sdk

when i select any item in listview(emulator)

Error shows like this..

application has stopped unexpectedly please try again

please help me

thanks for your replay
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Postby qlimax » Wed Nov 18, 2009 1:32 pm

window->show view->other..->android->logcat

then the logcat is show near the console.

logcat will show you what the error is produced.

also logcat is a good tool for debug...if in std java is System.out.println(""); in android is Log.v("tag","message");

post full the error pls :) (is printed in red in the logcat)

bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

ListActivity

Postby rajeshcit » Thu Nov 19, 2009 6:58 am

hai,

thanks for your replay.now its working in switching from Listactivity to Activity.

problem there in switching Listactivity to Listactivity.

Error is--------

11-19 11:22:50.359: INFO/ActivityManager(572): Starting activity: Intent { comp={com.test/com.test.ListActives} (has extras) }

11-19 11:22:50.438: DEBUG/AndroidRuntime(740): Shutting down VM

11-19 11:22:50.438: WARN/dalvikvm(740): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)

11-19 11:22:50.448: ERROR/AndroidRuntime(740): Uncaught handler: thread main exiting due to uncaught exception

11-19 11:22:50.468: ERROR/AndroidRuntime(740): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.ListActives}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ActivityThread.access$1800(ActivityThread.java:112)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.os.Handler.dispatchMessage(Handler.java:99)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.os.Looper.loop(Looper.java:123)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ActivityThread.main(ActivityThread.java:3948)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at java.lang.reflect.Method.invokeNative(Native Method)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at java.lang.reflect.Method.invoke(Method.java:521)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at dalvik.system.NativeStart.main(Native Method)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ListActivity.onContentChanged(ListActivity.java:236)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:312)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.Activity.setContentView(Activity.java:1626)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at com.test.ListActives.onCreate(ListActives.java:16)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)

11-19 11:22:50.468: ERROR/AndroidRuntime(740): ... 11 more

11-19 11:22:50.478: INFO/Process(572): Sending signal. PID: 740 SIG: 3

11-19 11:22:50.488: INFO/dalvikvm(740): threadid=7: reacting to signal 3

11-19 11:22:50.568: INFO/dalvikvm(740): Wrote stack trace to '/data/anr/traces.txt'

11-19 11:22:52.187: INFO/Process(740): Sending signal. PID: 740 SIG: 9

11-19 11:22:52.199: INFO/ActivityManager(572): Process com.test (pid 740) has died.

11-19 11:22:52.219: INFO/WindowManager(572): WIN DEATH: Window{4367de70 com.test/com.test.lists paused=false}

11-19 11:22:52.229: INFO/ActivityManager(572): Start proc com.test for activity com.test/.lists: pid=746 uid=10022 gids={}

11-19 11:22:52.409: INFO/jdwp(746): received file descriptor 13 from ADB

11-19 11:22:52.538: WARN/System.err(746): Can't dispatch DDM chunk 4d505251: no handler defined

11-19 11:22:52.798: WARN/InputManagerService(572): Got RemoteException sending setActive(false) notification to pid 740 uid 10022


please help me

its possible to switch between Listactivity in android
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Postby qlimax » Thu Nov 19, 2009 10:59 am

ok,
can you post the listactivity's xml?

I think you have some wrong there.
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

ListActivity

Postby rajeshcit » Thu Nov 19, 2009 11:15 am

hai,

xml for first ListActivity is

<?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="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>


xml file for second list activity is

<?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="@+id/android:list12"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>

intent for next listactivity description in first listactivity

Intent intent=new Intent(lists.this,ListActives.class);
intent.putExtra("values",str);
startActivity(intent);

ListActivity.java file details

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
savedInstanceState=this.getIntent().getExtras();
strs=savedInstanceState.getString("values");
//if(strs.equalsIgnoreCase("Barack Obama"))
//{
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, presidents));
//}
}

please help

thanks for your replay
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Re: ListActivity

Postby qlimax » Thu Nov 19, 2009 11:36 am

rajeshcit wrote:hai,


xml file for second list activity is

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.  xmlns:android="http://schemas.android.com/apk/res/android"
  4.  android:layout_width="wrap_content"
  5.  android:layout_height="wrap_content">
  6.    <ListView android:id="@+id/android:list12"
  7.        android:layout_width="fill_parent"
  8.        android:layout_height="fill_parent" />
  9.  
  10. </LinearLayout>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4




<ListView android:id="@+id/android:list12"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

should be

<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />


btw

is that ListActives.class "listactives" class name correct ?:)


bye.
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

ListActivity

Postby rajeshcit » Thu Nov 19, 2009 11:42 am

hai

very very thanks boss,now its working
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Postby qlimax » Thu Nov 19, 2009 12:20 pm

:mrgreen: :run: bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby ronyfederer » Tue Nov 24, 2009 10:50 am

Rajesh,
It would be of tremendous help if you could provide the entire package of the sample example you just discussed above.
I am also an android newbie. So, i can study and understand the concept quiet clearly if you do so.
die hard determination and hardcore professionalism can work out wonders...
ronyfederer
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Nov 24, 2009 10:46 am

ListActivity

Postby rajeshcit » Thu Nov 26, 2009 8:04 am

hai

Please find attached document.this example project contains switch between listactvity and switch between listactivity to activity

thanks & regards
Rajesh
Attachments
ListExamples.zip
(28.04 KiB) Downloaded 98 times
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Postby ronyfederer » Thu Nov 26, 2009 8:12 am

Thanks alot. I will go through the same.

By the way, would you mind sharing ur gtalk ID so that we can be partners sharing our personal experience and expertise on android programming.

aneesahamedaa is my gtalk id.

If you wish, u can add me and can share ur id to me also.
die hard determination and hardcore professionalism can work out wonders...
ronyfederer
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Nov 24, 2009 10:46 am

Postby rajeshcit » Thu Nov 26, 2009 8:20 am

hai

Please accept request in gtalk.my id is -rajeshpillai23

thanks
reagrds
rajeshcit
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 18, 2009 9:38 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests