ListView Toast Message - android

I have this code here. I am trying to display a toast message when a row in my list view is clicked but nothing shows up. Here is my code.
public class MainActivity extends AppCompatActivity {
ListView list;
String[] movieTitles;
int[] images = {R.drawable.batman_vs_superman, R.drawable.captain_america, R.drawable.deadpool,
R.drawable.jungle_book, R.drawable.xmen,R.drawable.zootopia, R.drawable.hail,R.drawable.allegent,
R.drawable.jason, R.drawable.lane};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res= getResources();
movieTitles = res.getStringArray(R.array.titles);
list = (ListView)findViewById(R.id.listView);
MoviesAdapter adapter = new MoviesAdapter(this,movieTitles, images);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "You selected "+ movieTitles[position], Toast.LENGTH_SHORT).show();
}
});
}
}
EDIT I have two xml files here is the code:
"content_main.xml"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.emmancipatemusemwa.task2.MainActivity"
tools:showIn="#layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clickable="true" />
</RelativeLayout>
And Here I have single_row.xml with the single row design.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:src="#drawable/captain_america"
android:paddingTop="10dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_toEndOf="#+id/imageView" />
<RatingBar
android:layout_width="245dp"
android:layout_height="wrap_content"
android:id="#+id/ratingBar"
android:layout_below="#+id/textView"
android:layout_toRightOf="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="more info"
android:id="#+id/textView2"
android:layout_below="#+id/ratingBar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textStyle="italic" />
</RelativeLayout>

Try this!!!!
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "You selected "+ position, Toast.LENGTH_SHORT).show();
}
});

DO LIKE THIS IN MAINACTIVITY
// Import
import android.widget.AdapterView;
.........
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "You selected "+ movieTitles[position], Toast.LENGTH_SHORT).show();
}
});
OR IN UR CUSTOM ADAPTER LISTVIEW ALTER/ADD THIS
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.program_list, null);
.....................
...................
...................
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "You selected "+result[position], Toast.LENGTH_LONG).show();
}
});
return rowView;
}
NOTE: Do Not have two setOnClickListener, Only one is used,
According to ur problem, I think ur using two setOnClickListener
functions so Toast Not working.
U should use only one in MainActivity or ur custom class (MovieAdapter).

Related

SetOnItemClickListener not responding in custom ListView of android

I am new to android,I am currently making a listview with custom list items,I want to do an action on Listview's item click event,I have searched so many similar threads with no luck,Can anyone help me to fix this.my code is as below,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<TextView
android:id="#+id/tv_hdr"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:background="#color/orange"
android:gravity="center"
android:text="SELECT YOUR CITY"
android:textColor="#color/white"
android:textSize="22dp" />
<EditText
android:id="#+id/et_search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_hdr"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="#drawable/et_selector"
android:drawableLeft="#drawable/search"
android:hint="City Or Postal Code"
android:padding="10dp"
android:textSize="16dp" />
<TextView
android:id="#+id/tv_loc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/et_search"
android:background="#color/grey_light"
android:drawableLeft="#drawable/ic_loc"
android:gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="5dp"
android:text=" My Location"
android:textColor="#color/black"
android:textSize="16dp"
android:textStyle="bold" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scr_location"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/tv_loc"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_populcar_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="5dp"
android:text=" Popular Cities"
android:textColor="#color/orange"
android:textSize="16dp"
android:textStyle="bold" />
<ListView
android:id="#+id/lv_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_populcar_city" />
<TextView
android:id="#+id/tv_states"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lv_city"
android:background="#color/white"
android:gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="5dp"
android:text="States"
android:textColor="#color/orange"
android:textSize="16dp"
android:textStyle="bold" />
<ListView
android:id="#+id/lv_state"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_states" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
adapter
public class CityAdapter extends BaseAdapter {
private Context mContext;
private final ArrayList<City> city;
Integer selected_position = -1;
public CityAdapter(Context c, ArrayList<City> city) {
mContext = c;
this.city = city;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return city.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.raw_city, parent, false);
} else {
v = (View) convertView;
}
TextView tv_city = (TextView) v.findViewById(R.id.tv_city);
tv_city.setText(city.get(position).getCity());
return v;
}
}
activity
lv_city.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Pref.setValue( SelectCity.this, Const.PREF_CITY_ID, cityList.get( position ).getCity_id() );
finish();//finishing activity
}
} );
You are wrong class in listview item click
lv_city.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Pref.setValue( SelectCity.this, Const.PREF_CITY_ID,
cityList.get( position ).getCity_id() );
finish();//finishing activity
}
});
#quick learner's was correct, But i put some idea for your ref..
If you use custom adapter class, In my suggestion use setOnClickListener in custom adapter class this is better way to do this type of case!!
For example,
mViewHolder.MyUI.setOnClickListener

onSelectedItem() returns null on listview.onSelectedItem

Java Code:
PhoneListAdapter adapter = new PhoneListAdapter(this,brands,models,price);
lv=(ListView)findViewById(R.Id.listView1);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> Parent,View view, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"listview clicked", Toast.LENGTH_LONG).show();
}
});
XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="80dp"
android:clickable="true">
</ListView>
</RelativeLayout></LinearLayout>
I have done everything, if i push a toast with hardcoded string, it appears, but any methods of listview return null. what am i missing???
#Piyush Gupta
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#33ffffff" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/imageView1"
android:layout_alignParentTop="true"
android:layout_marginTop="10dip"
android:layout_toRightOf="#+id/imageView1"
android:text="Textview"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
Hey Use somethid like below, if brands,models,price are arrayLists.
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> Parent,View view, int position,
long id) {
// TODO Auto-generated method stub
Assign the String or integer what ever you want. = brands .get(position).get if you have getter and setter methods.
Toast.makeText(getApplicationContext(),"listview clicked", Toast.LENGTH_LONG).show();
}
});

Can't get text from a textview in a listview

I have a custom cursor adapter CAdapter having the following lines of code:
public class CAdapter extends CursorAdapter {
public CAdapter(Context context, Cursor c) {
super(context, c);
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
TextView titleTV = (TextView) view.findViewById(R.id.listTitle);
titleTV.setText("#"+cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1)))+" "+
cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2))));
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.row_item_layout, parent, false);
return retView;
}
}
row_item_layout.xml file is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/listTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/heartIV"
android:focusable="false"
android:gravity="center_vertical"
android:text="Example application"
android:textSize="26sp"
android:paddingBottom="3dp"/>
<ImageView
android:id="#+id/heartIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/listTitle"
android:src="#drawable/heart"
android:paddingRight="5dp"
android:paddingLeft="2dp"/>
</RelativeLayout>
The activity FavListActivity displays the list. Its layout file is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.xkcdreader.FavListActivity"
tools:ignore="MergeRootFrame" >
<ListView
android:id="#+id/favL"
android:layout_width="match_parent"
android:layout_height="452dp"
android:layout_alignParentBottom="true"
android:layout_below="#+id/headingTV" >
</ListView>
<TextView
android:id="#+id/headingTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:text="Favourites"
android:textSize="25dp" />
</RelativeLayout>
Following is a section of code from FavListActivity
listView = (ListView) findViewById(R.id.favL);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("App", "clicked on item: " + position);
TextView listTV=(TextView) view.findViewById(R.id.titleTV);
Log.d("App",listTV.getText().toString());
}
});
On running this I get NullPointerException at the line Log.d("App",listTV.getText().toString()); The list does not having any null textview. I can't figure out the problem. Please help
you should use getItemAtPosition:
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor mycursor = (Cursor)parent.getItemAtPosition(position);
}
});
and use myCursor to access your data.
Try this..
Your TextView id is listTitle but you have mentioned as titleTV change that and try it.
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("App", "clicked on item: " + position);
TextView listTV=(TextView) view.findViewById(R.id.listTitle);
Log.d("App",listTV.getText().toString());
}
});
There is no TextView in row_item_layou.xml with id titleTV. So when you initialize you end up getting NUllPointerException.
Change this
TextView listTV=(TextView) view.findViewById(R.id.titleTV);
to
TextView listTV=(TextView) view.findViewById(R.id.listTitle);
since you have
<TextView
android:id="#+id/listTitle" // id is listTitle
Although your NPE can be solved as above you are better off using blackbet's answer
Cursor mycursor = (Cursor)parent.getItemAtPosition(position);
Then get the String using the mycursor.

Get Item from a ListView

My app is displaying 3 String with 3 Text-view in a list-view.
My Problem is that I create on layout for my list-view and i am not able to get the item from the first text view in the onListItemClick method.
How can I achieve achievement this?
Layout of the ListView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/outputlayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#color/ligthgrey">
<TextView
android:id="#+id/txOutputDeparture"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Abfahrt "
android:textColor="#color/black"
android:layout_alignParentLeft="true"
android:maxLength="#android:integer/config_shortAnimTime"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/txOutputDuration"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/txOutputDeparture"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Dauer"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/txOutputTransition"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/txOutputDuration"
android:text="Umstieg"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="5dp" />
</RelativeLayout>
Method where i create and fill the listView and its and ListActivity
public void getRoute() {
mdbH = new DatabaseHelperActivity(this);
cursor = mdbH.fetchallRoutes(intent.getStringExtra("StartHaltestelle"),intent.getStringExtra("ZielHaltestelle"), intent.getStringExtra("Zeit"));
ArrayList<DefineRouteActivity> route = new ArrayList<DefineRouteActivity>();
while(cursor.moveToNext()) {
route.add(new DefineRouteActivity(cursor.getString(0),cursor.getString(2),cursor.getString(4)));
}
ArrayAdapter<DefineRouteActivity> adapter = new RouteAdapterActivity(this, route);
setListAdapter(adapter);
}
AdapterActivity:
Activity context;
ArrayList<DefineRouteActivity> arraylist;
public RouteAdapterActivity(Activity context, ArrayList list) {
super(context,R.layout.outputlayout,list);
this.context = context;
arraylist = list;
}
#Override
public int getCount() {
return arraylist.size();
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View contentview, ViewGroup viewGroup) {
DefineRouteActivity routeItems = arraylist.get(position);
LayoutInflater inflater = context.getLayoutInflater();
View view = inflater.inflate(R.layout.outputlayout,null);
TextView tvDeparture = (TextView)view.findViewById(R.id.txOutputDeparture);
tvDeparture.setText(routeItems.getAbfahrtszeit());
TextView tvDuration = (TextView)view.findViewById(R.id.txOutputDuration);
tvDuration.setText(routeItems.getDauer());
TextView tvTransition = (TextView)view.findViewById(R.id.txOutputTransition);
tvTransition.setText(routeItems.getUmstieg());
return view;
}
Here is my onClick Method:
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
((View)v).
Intent detail = new Intent(getApplicationContext(),DetailOutputActivity.class);
detail.putExtra("StartStop",l.getItemAtPosition(0).toString());
detail.putExtra("EndStop","ich");
detail.putExtra("Time","du");
detail.putExtra("Route","er");
startActivity(detail);
}
Here is my Layout containing the listView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
You need another xml containing the listView.
For example: sample.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
In your mainActivity.java:
setContentView(R.layout.sample.xml);
lv = (ListView)findViewById(R.id.lv1);
lv.setOnItemClickListener(this);
Your listActivity must implement OnItemClickListener.
Then implements onItemClick method. Example:
#Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
// TODO Auto-generated method stub
int id_object = ((object)a.getAdapter().getItem(position)).getIdInstalacion();
Intent i = new Intent(this, Other.class);
i.putExtra("id_", id_object);
startActivity(i);
}

ListView does not react to selection

I have a ListView in an activity which does note react to being selected. This could be a small thing as I am relatively new to Android, but don't seem to be able to figure it out myself.
My onLoad() in my Activity loads like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.article_list);
Bundle extras = getIntent().getExtras();
if(extras != null){
if(extras.containsKey("categoryId")) categoryId = extras.getLong("categoryId");
}
ListView lv = (ListView) findViewById(R.id.article_list_activity);
iDomsAndroidApp app = ((iDomsAndroidApp) getApplicationContext());
try {
objects = app.getDataManager().getArticlesForCategory(categoryId, 15);
adapter = new ArticleListAdapter(this, R.layout.article_list_cell, objects, categoryId);
lv.setOnScrollListener(adapter);
lv.setAdapter(adapter);
} catch (Exception e){
Log.e(iDomsAndroidApp.TAG, "Error " + e.getMessage(), e);
}
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(), objects.get(position).getTitle(),
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(view.getContext(), ArticleActivity.class);
intent.putExtra("articleId", objects.get(position).getId());
startActivity(intent);
}
});
}
Then in my Adapter (ArrayAdapter)
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (view == null) {
view = inflater.inflate(R.layout.article_list_cell, viewGroup, false);
}
Article article = getItem(i);
TextView titleText = (TextView)view.findViewById(R.id.article_list_titleText);
try{
TextView siteText = (TextView)view.findViewById(R.id.article_list_siteText);
TextView summaryText = (TextView)view.findViewById(R.id.article_list_summaryText);
RadioButton readBttn = (RadioButton) view.findViewById(R.id.article_list_readButton);
TextView updatedText = (TextView) view.findViewById(R.id.article_list_updatedText);
TextView date = (TextView) view.findViewById(R.id.article_cell_date);
titleText.setText(article.getTitle());
siteText.setText(article.getSite().getName());
summaryText.setText(article.getSummary());
date.setText(DateFormat.getMediumDateFormat(this.getContext()).format(article.getPubDate()));
if(article.getRead()){
readBttn.setChecked(false);
} else {
readBttn.setChecked(true);
}
if(article.getUpdated()){
updatedText.setVisibility(View.VISIBLE);
} else {
updatedText.setVisibility(View.INVISIBLE);
}
} catch (Exception e) {
titleText.setText("Error loading article content!");
}
return view;
}
article_list_cell.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Site"
android:id="#+id/article_list_siteText" android:paddingLeft="10dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Today 12:34"
android:id="#+id/article_cell_date"
android:gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="80dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:gravity="center">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/article_list_readButton" android:checked="false"
android:paddingTop="5dp"
android:paddingBottom="5dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Updated"
android:id="#+id/article_list_updatedText" android:textColor="#1898ff"
android:layout_gravity="right"
android:visibility="visible"
android:textSize="12dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/list_background_overlay">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:id="#+id/article_list_titleText" android:maxLines="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Summary"
android:id="#+id/article_list_summaryText" android:maxLines="3"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
My guess is RadioButton takes focus when you click list item.
So add
android:descendantFocusability="blocksDescendants"
to root element in article_list_cell.xml
Edit:
Try to add #Override to your onItemClick method
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {}
l1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String name=(String)parent.getItemAtPosition(position);
Toast.makeText(getBaseContext(), name, Toast.LENGTH_LONG).show();
Intent i = new Intent(getBaseContext(),Webview.class);
//i.putExtra("USERNAME", name);
startActivity(i);
}
});

Categories

Resources