Thursday, April 24, 2014

listview accepted interface data, click on each item to jump to the corresponding Activity


listview accepted interface data, click on each item to jump to the corresponding Activity.
Which big God Demo, single step also, for example, part of the interface data into listview
Click the item to jump to the corresponding part of the
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
A part of the property of the interface to return data into the collection, loaded with the adapter to the listview above, you can choose to install the collection inside an object, object encapsulates multiple properties, for the first time when the show just take the object, and then give listview setting item Click on an event listener, you will get the subscript collection click, and then taken out into the corresponding item.
Reply:
Bean class:
 public class PojoEnter {

private String aaa;
private String bbb;
private String ccc;
private String ddd;
public String getAaa () {
return aaa;
}
public void setAaa (String aaa) {
this.aaa = aaa;
}
public String getBbb () {
return bbb;
}
public void setBbb (String bbb) {
this.bbb = bbb;
}
public String getCcc () {
return ccc;
}
public void setCcc (String ccc) {
this.ccc = ccc;
}
public String getDdd () {
return ddd;
}
public void setDdd (String ddd) {
this.ddd = ddd;
}
}


Adapter class:

 public class TestAdapter extends BaseAdapter {

private Context mContext;
private List mList;

public TestAdapter (Context context, List list) {
mContext = context;
mList = list;
}


public void setList (List list) {
mList = list;
}

@ Override
public int getCount () {

return mList.size ();
}

@ Override
public Object getItem (int position) {

return position;
}

@ Override
public long getItemId (int position) {

return position;
}

@ Override
public View getView (int position, View convertView, ViewGroup parent) {
HolderView holder = null;
if (convertView == null) {
holder = new HolderView ();
/ / Modify to your own layout
convertView = LayoutInflater.from (mContext) inflate (R.layout.xxxxx, null);.
holder._text1 = (TextView) convertView.findViewById (R.id.xxxxx);
holder._text2 = (TextView) convertView.findViewById (R.id.xxxxx);
holder._text3 = (TextView) convertView.findViewById (R.id.xxxxx);
holder._text4 = (TextView) convertView.findViewById (R.id.xxxxx);
convertView.setTag (holder);

} Else {
holder = (HolderView) convertView.getTag ();
}

/ **
* Add the data how and how,
* /
if (mList.get (position)) {
/ **
* Go to a Activity in
* /
convertView.setOnClickListener (new OnClickListener () {

@ Override
public void onClick (View arg0) {
/ / Jump to a Activity in
}
});
}



return null;
}

/ **
* This is the List item inside the assembly, according to your own
* Modify
* @ Author Administrator
* /
class HolderView {
TextView _text1;
TextView _text2;
TextView _text3;
TextView _text4;
}

}


Activity category:

 public class TestActivity extends Activity {

private TestAdapter mAdapter;
private List mList;
private ListView myListView;

@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
/ / MyListView = () zxxxxxxx; instantiated
mAdapter = new TestAdapter (this, new ArrayList ());
myListView.setAdapter (mAdapter);
requestData ();
}

private void requestData () {
/ **
* There refresh the data
* /
}

}

Reply:
cited a floor u014635668 reply:
interface returns data into the collection, loaded with the adapter to the listview above, you can choose to install the collection inside an object, the object a part of the property when the package more than one property, just take the first display of the object, and then give listview Set item click event listener, you get after clicking the subscript of the collection, and then taken out on a place corresponding item.

I would say so. . .
Reply:
reference to the second floor dancing_with_wolf reply:
Bean class:
 public class PojoEnter {

private String aaa;
private String bbb;
private String ccc;
private String ddd;
public String getAaa () {
return aaa;
}
public void setAaa (String aaa) {
this.aaa = aaa;
}
public String getBbb () {
return bbb;
}
public void setBbb (String bbb) {
this.bbb = bbb;
}
public String getCcc () {
return ccc;
}
public void setCcc (String ccc) {
this.ccc = ccc;
}
public String getDdd () {
return ddd;
}
public void setDdd (String ddd) {
this.ddd = ddd;
}
}


Adapter class:

 public class TestAdapter extends BaseAdapter {

private Context mContext;
private List mList;

public TestAdapter (Context context, List list) {
mContext = context;
mList = list;
}


public void setList (List list) {
mList = list;
}

@ Override
public int getCount () {

return mList.size ();
}

@ Override
public Object getItem (int position) {

return position;
}

@ Override
public long getItemId (int position) {

return position;
}

@ Override
public View getView (int position, View convertView, ViewGroup parent) {
HolderView holder = null;
if (convertView == null) {
holder = new HolderView ();
/ / Modify to your own layout
convertView = LayoutInflater.from (mContext) inflate (R.layout.xxxxx, null);.
holder._text1 = (TextView) convertView.findViewById (R.id.xxxxx);
holder._text2 = (TextView) convertView.findViewById (R.id.xxxxx);
holder._text3 = (TextView) convertView.findViewById (R.id.xxxxx);
holder._text4 = (TextView) convertView.findViewById (R.id.xxxxx);
convertView.setTag (holder);

} Else {
holder = (HolderView) convertView.getTag ();
}

/ **
* Add the data how and how,
* /
if (mList.get (position)) {
/ **
* Go to a Activity in
* /
convertView.setOnClickListener (new OnClickListener () {

@ Override
public void onClick (View arg0) {
/ / Jump to a Activity in
}
});
}



return null;
}

/ **
* This is the List item inside the assembly, according to your own
* Modify
* @ Author Administrator
* /
class HolderView {
TextView _text1;
TextView _text2;
TextView _text3;
TextView _text4;
}

}


Activity category:

 public class TestActivity extends Activity {

private TestAdapter mAdapter;
private List mList;
private ListView myListView;

@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
/ / MyListView = () zxxxxxxx; instantiated
mAdapter = new TestAdapter (this, new ArrayList ());
myListView.setAdapter (mAdapter);
requestData ();
}

private void requestData () {
/ **
* There refresh the data
* /
}

}


Great God, requestData which specifically how to write, there is no template, I rookie
Reply:
I would not, Bangding
Reply:
In your data model which corresponds to a different activity should have a member variable, right? For example, in accordance with specific information area inside the launcher app of startactivity

No comments:

Post a Comment