onclick open new view

Put your problem here if it does not fit any of the other categories.

onclick open new view

Postby dutch85 » Mon Jun 28, 2010 11:15 pm

I am trying to create a list view where each item will open up a new view and display a picture and text describing the item when said item is selected. I am working with this tutorial

novice-tutorials-f8/opening-windows-i-e-webbrowser-reacting-on-clicks-t22.html?hilit=reacting%20on%20Clicks

so is there a way i can use this code to open up a new view

Code: Select all
@Override
    protected void onListItemClick(ListView l, View v, int position, long id){
       super.onListItemClick(l, v, position, id);
       
       // Get the item that was clicked
       Object o = this.getListAdapter().getItem(position);
       String keyword = o.toString();

       // Create an VIEW intent
       Intent myIntent = null;
      // The intent will open our anddev.org-board and search for the keyword clicked.
      myIntent = new Intent("android.intent.action.VIEW",
         Uri.parse ("" + keyword + "")
         );
      // Start the activity
       startActivity(myIntent);
    }
}
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Top

Re: onclick open new view

Postby dutch85 » Tue Jun 29, 2010 1:05 am

so my code now reads as the following but my app crashes every time a list item is clicked.

Code: Select all
@Override
    protected void onListItemClick(ListView l, View v, int position, long id){
       super.onListItemClick(l, v, position, id);
       
       {
           if (position == 0){
               setContentView(R.layout.android);
               };
           if (position == 1){
               setContentView(R.layout.google);
               };
           if (position == 2){
               setContentView(R.layout.eclipse);
               };
          
               }
                }
                     }
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: onclick open new view

Postby anarche » Tue Jun 29, 2010 5:40 am

Whats the error?
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: onclick open new view

Postby dutch85 » Tue Jun 29, 2010 6:19 am

It's an extremely generic error.

"The application SPR2 (process org.dutch.spr) has stopped unexpectedly. Please try again."

edit:
also there are no syntax errors
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: onclick open new view

Postby anarche » Tue Jun 29, 2010 6:29 am

Please post your logcat
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: onclick open new view

Postby dutch85 » Tue Jun 29, 2010 6:51 am

Code: Select all
I/ActivityManager(   51): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.dutch.spr/.main }
I/ActivityManager(   51): Start proc org.dutch.spr for activity org.dutch.spr/.main: pid=218 uid=10046 gids={1015}
D/ddm-heap(  218): Got feature list request
I/ARMAssembler(   51): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x49eb00:0x49ec7c] in 1152729 ns
I/ARMAssembler(   51): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x49ec80:0x49ed8c] in 830222 ns
I/ActivityManager(   51): Displayed activity org.dutch.spr/.main: 1243 ms (total 1243 ms)
I/ARMAssembler(   51): generated scanline__00000077:03545404_00000A04_00000000 [ 29 ipp] (51 ins) at [0x49ed90:0x49ee5c] in 638599 ns
D/AndroidRuntime(  218): Shutting down VM
W/dalvikvm(  218): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime(  218): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  218): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
E/AndroidRuntime(  218):    at android.app.ListActivity.onContentChanged(ListActivity.java:236)
E/AndroidRuntime(  218):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
E/AndroidRuntime(  218):    at android.app.Activity.setContentView(Activity.java:1622)
E/AndroidRuntime(  218):    at org.dutch.spr.main.onListItemClick(main.java:76)
E/AndroidRuntime(  218):    at android.app.ListActivity$2.onItemClick(ListActivity.java:312)
E/AndroidRuntime(  218):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime(  218):    at android.widget.ListView.performItemClick(ListView.java:3285)
E/AndroidRuntime(  218):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
E/AndroidRuntime(  218):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(  218):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(  218):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  218):    at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(  218):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  218):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  218):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  218):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  218):    at dalvik.system.NativeStart.main(Native Method)
I/Process (   51): Sending signal. PID: 218 SIG: 3
I/dalvikvm(  218): threadid=7: reacting to signal 3
I/dalvikvm(  218): Wrote stack trace to '/data/anr/traces.txt'
I/ARMAssembler(   51): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x4be858:0x4be914] in 491888 ns
I/ARMAssembler(   51): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x4be918:0x4beae0] in 574012 ns
I/Process (  218): Sending signal. PID: 218 SIG: 9
I/WindowManager(   51): WIN DEATH: Window{43d90278 org.dutch.spr/org.dutch.spr.main paused=false}
I/ActivityManager(   51): Process org.dutch.spr (pid 218) has died.
I/UsageStats(   51): Unexpected resume of com.android.launcher while already resumed in org.dutch.spr
W/InputManagerService(   51): Got RemoteException sending setActive(false) notification to pid 218 uid 10046
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Top

Re: onclick open new view

Postby anarche » Tue Jun 29, 2010 7:46 am

lemme guess - your Activity extends ListActivity???

tell me what this error message means to you:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. E/AndroidRuntime(  218): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
  2.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: onclick open new view

Postby dutch85 » Wed Jun 30, 2010 1:21 am

my main.xml looks like the following that error means my main.xml is missing the line 'android:id="@android:id/list">' correct?

Code: Select all
<?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"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

<ListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:cacheColorHint="#00000000"
    android:id="@android:id/list">
</ListView>


</LinearLayout>
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: onclick open new view

Postby anarche » Wed Jun 30, 2010 2:09 am

exactly!

You can use "android:id="@+id/list" I believe

Please read and post logcats in the future. It makes helping you a lot easier
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: onclick open new view

Postby dutch85 » Wed Jun 30, 2010 2:19 am

well I am still receiving the same error in logcat even with 'android:id="@android:id/list">' in my main.xml i have also tried "android:id="@+id/list" and i continue receiving the "java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'" error
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: onclick open new view

Postby anarche » Wed Jun 30, 2010 2:23 am

try importing android.R.id
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: onclick open new view

Postby dutch85 » Wed Jun 30, 2010 4:04 am

no luck still same error with "import android.R.id"

here is all my code

main.java
Code: Select all
package org.dutch.spr;

import java.net.URISyntaxException;
import android.R.id;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class main extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // Create an array of Strings, that will be put to our ListActivity
        String[] mStrings = new String[]{"android", "google", "eclipse"
};
        // Create an ArrayAdapter, that will actually make the Strings above appear in the ListView
        this.setListAdapter(new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, mStrings));
    }
   
   @Override
   protected void onListItemClick(ListView l, View v, int position, long id){
       super.onListItemClick(l, v, position, id);
       

       
       {
           if (position == 0){
              this.setContentView(org.dutch.spr.R.layout.android);
           }
           if (position == 1){
              this.setContentView(org.dutch.spr.R.layout.google);
           }
           if (position == 2){
              setContentView(org.dutch.spr.R.layout.eclipse);
           }
          
               }
                }
                     }


main.xml
Code: Select all
<?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"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

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


AndroidManifest.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.dutch.spr"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".main"
                  android:label="@string/app_name">
                 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
           
        </activity>

    </application>


</manifest>
Last edited by dutch85 on Wed Jun 30, 2010 4:49 am, edited 1 time in total.
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: onclick open new view

Postby anarche » Wed Jun 30, 2010 4:32 am

ok edit: try import android.R

or else (get rid of that and) import <your package>.R - this includes the main.xml resource that your Activity needs. i expect the error message would be different if your own resource file was missing

don't know if that'll fix it, if not you might have to wait. Everything else looks fine...
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: onclick open new view

Postby dutch85 » Wed Jun 30, 2010 4:58 am

ya it's still a no go although one interesting thing is that when i imported "import org.dutch.spr.R;" it was not underlined in yellow as "not in use" like "import android.R.id;" and "import android.R;" were, but I am still receiving the same error in log cat.
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: onclick open new view

Postby anarche » Wed Jun 30, 2010 5:16 am

This may be a silly question, but are you setting your contentView?? I can't seem to see it in onCreate() ???
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests