Opening windows (i.e. webbrowser) / reacting on Clicks

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby ramgraph1 » Sun Mar 16, 2008 2:41 am

This tutorial was very helpful and I could use it with no problem in one of my apps. But now I am dealing with a different kind of ListView - a SimpleCursorAdapter instead of an ArrayAdapter. The fetchAllUsers part below is working correctly, but the onListItemClick part is returning this text below instead of the text from the ListItem that is getting clicked:

android.database.sqlite.SQLiteCursor@40199e08

How can I change the onListItemClick so that it will work right with a SimpleCursorAdapter?
Code: Select all
Cursor c = dbhelper.fetchAllUsers();
       startManagingCursor(c);
       String[] from = new String[] { UserDB.KEY_username };
       int[] to = new int[] { R.id.text1};
        SimpleCursorAdapter userfind =
           new SimpleCursorAdapter(this, R.layout.userlist, c, from, to);
        setListAdapter(userfind);
}
  @Override
    protected void onListItemClick(ListView l, View v, int position, long id){
     super.onListItemClick(l, v, position, id);
     Object o = this.getListAdapter().getItem(position);
     String uname = o.toString();
     username.setText(uname);
    }

Thanks.
ramgraph1
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Wed Jan 09, 2008 10:03 pm

Top

i have one problem some body help me out plz

Postby pattasri » Sat Mar 22, 2008 2:01 pm

i got this error in exicuting the above code.......and it says like this at line :--


CODE:- catch (URISyntaxException e) {
e.printStackTrace();
}

ERROR:-Unreachable catch block for URISyntaxException. This exception is never thrown from the try
statement body..


and also should i have to do some thing for this ..........line


CODE:- this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mStrings));


should i create anything like "simple_list_item_1" in the "R.layout" in my present project ........where in there is only one MAIN.xml file present shall i need to create xml file with name "simple_list_item_1" if so wat should i do in tat ........plz do help me out in it..
pattasri
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 13, 2008 4:58 pm
Location: india

need help

Postby hanooollly » Sun Mar 30, 2008 11:50 am

plusminus wrote:Hello nithin.warier,

since m5 it is [font=Lucida Console]android.net.Uri[/font].

Regards,
plusminus




I imported android.net.Uri but the error still there iam using m5
webIntent = new Intent("android.intent.action.VIEW",new Uri("http://www.google.com"));
it cannt be compiled

thanx alot
hany saleh
Hany Saleh
Java Programer
MobiArab
User avatar
hanooollly
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 05, 2008 10:37 am
Location: egypt

Re: need help

Postby plusminus » Sun Mar 30, 2008 3:27 pm

hanooollly wrote:
plusminus wrote:Hello nithin.warier,

since m5 it is [font=Lucida Console]android.net.Uri[/font].

Regards,
plusminus




I imported android.net.Uri but the error still there iam using m5
webIntent = new Intent("android.intent.action.VIEW",new Uri("http://www.google.com"));
it cannt be compiled

thanx alot
hany saleh

Hello hany saleh,

The Uri-class is abstract (you cannot create objects of it!), but provides some static functions, like Uri.parse(String s):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. webIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com"));
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Re: i have one problem some body help me out plz

Postby plusminus » Sun Mar 30, 2008 3:32 pm

Hello pattasri,

pattasri wrote:i got this error in exicuting the above code.......and it says like this at line :--
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. catch (URISyntaxException e) {
  2.      e.printStackTrace();
  3. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


ERROR:-Unreachable catch block for URISyntaxException. This exception is never thrown from the try
statement body..

You are using [font=Lucida Console]Uri.parse("bla");[/font] :?: As it doesn't throw an Exception, you can delete it (the m3-code did, indeed).

pattasri wrote:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings));
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



should i create anything like "simple_list_item_1" in the "R.layout" in my present project ........where in there is only one MAIN.xml file present shall i need to create xml file with name "simple_list_item_1" if so wat should i do in tat ........plz do help me out in it..

No you do not need to, as we are using a pre-defined layout-item here (it comes from the android.R-class noch from our R.java!)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby bjreddi » Mon Apr 07, 2008 12:47 pm

Hi plusminus,

When i tried this Opening Windows in Webbrowser example.
Code worked without any problems after using android.net.uri;

But after i run it, when i click on android, it starts searching for it. but never opens the android web page..?

it is just searching and searching .. but no result..

Can u tell me why?

Thanks,
jyo
bjreddi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 03, 2008 1:24 pm

Top

Postby arams » Wed May 20, 2009 10:09 am

The follwing code works welll....[code]package com.rams;

import android.app.Activity;
import android.os.Bundle;
import java.net.URISyntaxException;
import android.net.Uri;
import android.app.ListActivity;
import android.content.Intent;
//import android.net.ContentURI;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ConnectLink 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);

// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(this, keyword,Toast.LENGTH_SHORT).show();
// Create an VIEW intent
Intent myIntent = null;
try {
// The intent will open our anddev.org-board and search for the keyword clicked.
// myIntent = new Intent("android.intent.action.VIEW",new ContentURI("http://anddev.org/search.php?mode=results&search_keywords='" + keyword + "'"));
if(keyword.equals("Google"))
myIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com"));
else if(keyword.equals("Android"))
myIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.anddev.org"));
else if(keyword.equals("Eclipse"))
myIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.eclipse.org"));
} catch (Exception e) {
e.printStackTrace();
}
// Start the activity
startActivity(myIntent);
}
}
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Postby enggvipin.singh » Tue Aug 18, 2009 1:03 am

bjreddi wrote:Hi plusminus,

When i tried this Opening Windows in Webbrowser example.
Code worked without any problems after using android.net.uri;

But after i run it, when i click on android, it starts searching for it. but never opens the android web page..?

it is just searching and searching .. but no result..

Can u tell me why?

Thanks,
jyo


bjreddi,

I beleive ur internet connection is not set up properly. Do te below steps-
Run from CMD
adb shell sqlite3 /data/data/com.google.android.providers.settings/databases/settings.db ""INSERT INTO system VALUES(99,'http_proxy','[HOST]:[PORT]');""


or if it throws error remove the slash""

adb shell sqlite3 /data/data/com.google.android.providers.settings/databases/settings.db "INSERT INTO system VALUES(99,'http_proxy','[HOST]:[PORT]');"


and even after this internet doesnot work proviode the settings in

Emulator>settings>wireless controls>mobile networks>APN>proxy,port,username,password

close the emulator and run it fresh.It should work.
User avatar
enggvipin.singh
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 12, 2009 4:16 pm
Location: INDIA

Re: Opening windows (i.e. webbrowser) / reacting on Clicks

Postby dutch85 » Mon Jun 28, 2010 12:04 pm

what would I do if I wanted to use this code to open a new view that displays a picture w/ a description of the keyword selected in the list.
dutch85
Developer
Developer
 
Posts: 39
Joined: Tue Apr 06, 2010 12:31 am

Re: Opening windows (i.e. webbrowser) / reacting on Clicks

Postby imhavoc » Mon Aug 23, 2010 11:11 pm

This code is no longer valid with the new API updates. It's very frustrating.

Any chance someone can update the code for the latest revs?
imhavoc
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 23, 2010 11:08 pm

Re: Opening windows (i.e. webbrowser) / reacting on Clicks

Postby Star » Fri Jan 06, 2012 11:31 am

:) I want to know, what is the difference between, "android.R.layout.simple_list_item_1", and "android.R.layout.simple_list_item_2" that we use in "setListAdapter"...? We usually use the first one, but I don't know, when can we use the second one?

when we click on item of listview, it opens webpage. But, how can we give the link to each items of listview?
Do I need to create, different "intents" individually for all items, or we can set the links, using array, as we use for items...


The last question is, in eclipse when we type defined variable or something like
"gobutton.setOnClickListener(new View. )",
and as we us dot(.) after View that we used here, we normally get options like "onclick listener", "onKey Listener" and other....,

But, when I do this, it doesn't show any options. so, Do I need to change the settings in eclipse for that?

Thank you very much in advance....
Star
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jan 06, 2012 7:18 am

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests