我有两个活动A和B.
在A活动中,我显示listview
中的所有记录。当用户单击活动A上列出的任何项目时,它应该重定向到下一个活动B,它应该显示该特定单个项目以及下一个/上一个按钮。
当用户点击“下一个”或“上一个”按钮时,应相应地更改该项目。
我应该使用listview
还是简单地使用textview来显示活动B上的特定记录,这些记录会更改上一个/下一个。怎么实现呢?
请帮帮我。 这是我的活动A
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_giga);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.out.println("My Exception 333: ");
loadNews();
}
private void loadNews(){
try{
BaseFeedParserGiga parser = new BaseFeedParserGiga();
messages = parser.parsse();
final String title[]= new String[messages.size()] ;
final String pubdate[]= new String[messages.size()] ;
final String link[]= new String[messages.size()] ;
final String Long[]= new String[messages.size()] ;
final String image[]= new String[messages.size()] ;
list = new ArrayList<String>(messages.size());
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (com.example.newsworld.MessageGiga msg : messages){
list.add(msg.getTitle());
title[j]=msg.getTitle();
pubdate[i]=msg.getPubdate();
link[m]=msg.getLink();
Long[l]=msg.getDesc();
Document doc = Jsoup.parse(Long[l]);
Elements links = doc.getElementsByTag("img");
String src = links.attr("src");
image[k]=src;
setListAdapter(new ArrayAdapter<String>(GigaActivity.this, R.layout.rows, list ){
@Override
public View getView(final int j, View convertView, ViewGroup parent) {
View row;
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, parent, false);
System.out.println("My Exception 5: ");
holder = new ViewHolder();
holder.txtclick= (TextView) convertView.findViewById(R.id.textView1);
holder.txtTitle = (TextView) convertView.findViewById(R.id.textView2);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String s=image[j];
holder.txtTitle.setText(title[j]+"\n\n"+pubdate[j]);
holder.txtclick.setOnClickListener( new OnClickListener()
{
public void onClick(View viewParam)
{
Intent in = new Intent(GigaActivity.this,GigaPage.class);
in.putExtra("title", title[j]);
in.putExtra("pubdate", pubdate[j]);
in.putExtra("link", link[j]);
startActivity(in);
overridePendingTransition(R.anim.grow_from_middle,R.anim.shrink_to_middle);
}
});
return convertView;
}
class ViewHolder {
TextView txtLat;
TextView txtTitle;
TextView txtPubdate;
ImageView txtLink;
TextView txtclick;
}
});
j++;
i++;
m++;
l++;
k++;
}
}catch(Exception exc){
System.out.println("My Exception : "+exc.getMessage());
}
}
答案 0 :(得分:0)
我想我会像你建议的那样布局B页面,就像一个带有一些箭头的TextViews的集合,或者通过遍历页面列表视图后面的光标来获取它的索引来检索适当的对象来检索适当的对象答:我也许也可以用侧滑手势做同样的事情。
ViewGroup pageB = (ViewGroup) ViewGroup.inflate(this, R.layout.pageB, null);
TextView textView = (TextView) pageB.findViewById(R.id.a_text_view);
listViewAdapter = new SimpleCursorAdapter(this, R.layout.listitem, listCursor, tableFromColumns, toListItemViews, 0);
listView.setAdapter(listViewAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listCursor.moveToPosition(position);
textView.setText(listCursor.getString(0)); //set textview on pageB with record data
setContentView(pageB);
}
});
void onClickNextRecord() {
listCursor.moveToNext(); // go to next record
textView.setText(listCursor.getString(0)); //update textview on pageB with next record data
}
答案 1 :(得分:0)
取一个字段Hashmap
HashMap<String,com.example.newsworld.MessageGiga> messages=new HashMap<String,com.example.newsworld.MessageGiga>();
in for loop
for (com.example.newsworld.MessageGiga msg : messages){
messages.put(msg.getTitle(),msg);
}
将其作为额外的意图发送,确保您的邮件已序列化
intent.putExtra("messages",messages);
在GigaPage中就像这样
if (getIntent().getSerializableExtra("messages") != null)
messages= (HashMap<String, com.example.newsworld.MessageGiga>) getIntent().getSerializableExtra("messages");
您还发送了用于填充列表视图的列表
首先获取所选项目的索引
int index = yourlist.indexOf(title) //here title is selected item title
获取当前标题的数据
com.example.newsworld.MessageGiga msg=messges.get(ttile);
它将返回包含消息相关标题
的所有信息的消息对象onClick 上一页减少索引
index=index-1;
title=yourlist.get(index);
com.example.newsworld.MessageGiga msg=messges.get(ttile);
为下一步做同样的事情,增加索引va; ue