listview layout has 16 entries (Item), how each item can jump to another Activity, I do, but there is no response, please give pointers about: the code is that these GroupActivity.java
package com.test.listview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class GroupActivity extends Activity {
private ListView listView;
private ListViewAdapter listViewAdapter;
private List
Adapter
package com.test.listview;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class ListViewAdapter extends BaseAdapter {
private Context context; / / run the context
private List> listItems; / / group list
private LayoutInflater layoutInflater; / / View container
protected SharedPreferences group_sp;
/ ** Custom list control collection * /
public final class ListItemView {
public ImageButton imageButton;
public TextView textView;
public ImageView imageView;
}
public ListViewAdapter (Context context, List> listItems) {
this.context = context;
layoutInflater = LayoutInflater.from (context) ;/ / create a view of the container to set the context
this.listItems = listItems;
}
public int getCount () {
return listItems.size ();
}
public Object getItem (int position) {
return listItems.get (position);
}
public long getItemId (int position) {
return position;
}
/ ** List list settings * /
public View getView (int position, View convertView, ViewGroup parent) {
/ / TODO Auto-generated method stub
convertView = layoutInflater.inflate (R.layout.group_list, null);
/ / Get the spatial object
final ImageButton imageButton = (ImageButton) convertView.findViewById (R.id.goff1);
imageButton.setBackgroundResource (R.drawable.goff1);
imageButton.setOnClickListener (new View.OnClickListener () {
boolean flag = true;
public void onClick (View v) {
if (flag) {
imageButton.setBackgroundResource (R.drawable.gon1);
flag = false;
} Else {
imageButton.setBackgroundResource (R.drawable.goff1);
flag = true;
}
}
});
TextView textView = (TextView) convertView.findViewById (R.id.title);
ImageView imageView = (ImageView) convertView.findViewById (R.id.right_image);
/ / ImageView.setOnClickListener (new View.OnClickListener () {
/ /
/ / @ Override
/ / Public void onClick (View v) {
/ / Intent intent = new Intent ();
/ / Intent.setClass (context, ListViewGroup.class);
/ / Context.startActivity (intent);
/ /}
/ /});
/ / Fill the text and pictures
imageButton.setBackgroundResource ((Integer) listItems.get (position) get ("imageButton").);
textView.setText ((String) listItems.get (position) get ("textView").);
imageView.setBackgroundResource ((Integer) listItems.get (position) get ("imageView").);
/ / AddListener (convertView);
return convertView;
}
}
Reply:
adb logcat E> e.log
Reply:
LZ not use startActivity (intent) do?

Reply:
Breakpoints
Reply:
If you want to start in onItemClick Activity, does not require using switch case in each row click to jump to a new Activity, use the following code to replace your:
listView.setOnItemClickListener (new OnItemClickListener () {
@ Override
public void onItemClick (AdapterView parent, View view, int position, long id) {
Log.i ("mm", "onItemClick");
Intent intent = new Intent (GroupActivity.this, ListViewGroup.class); GroupActivity.this.startActivity (intent);}
}); Reply:
Do not use the application context, try using Activity context:
intent.setClass (GroupActivity.this, ListViewGroup.class);
Reply:
Reply:
Ah, has been solved
Reply:
The landlord how to solve, I also teach experience points to it, thank you
No comments:
Post a Comment