如何限制" onListItemClick"到时间范围? [英] How to limit "onListItemClick" to Time Range?
本文介绍了如何限制" onListItemClick"到时间范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个的ListView 在我的项目和清单显示数据从数据库(sqlite的)。
I Have One ListView in My Project and that List Show Data from Database (sqlite).
public void refreshDisplay() {
ArrayAdapter<MyStory> adapter = new StoryAdapter(this, story);
setListAdapter(adapter);
}
结果和onListItemClick code:
and onListItemClick code:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
MyStory story = stories.get(position);
Intent next = new Intent(this, ShowStory.class);
next.putExtra("thisstory", story);
startActivity(next);
}
结果现在,我可以设置只在特定日期启用/禁用ListView项?例如,一个故事只可读(点击)如果系统日期是(为前。)听英语6月29日?
结果是否有需要在数据库中为每个故事添加日期列?
结果MainActivity完成code是:
Now, can i set enable/disable ListView Item only in the specific dates? for example one Story only readable (clickable) if system date is (for ex.) 29 June 2014?.
Is there a need to add a Date column in the Database for each Story?
MainActivity Complete code is:
public class MainActivity extends ListActivity {
DBAdapter db;
List<MyStory> stories;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = getListView();
db = new DBAdapter(getBaseContext());
db.open();
stories = db.getAllContacts();
if (stories.size() == 0) {
String destPath = "/data/data/" + getPackageName() + "/databases";
try {
CopyDB(getBaseContext().getAssets().open("StoryDB"),
new FileOutputStream(destPath + "/stories"));
Log.i(DBAdapter.TAG, "DB Copy-OK");
stories = db.getAllContacts();
refreshDisplay();
Log.i(DBAdapter.TAG, storiess.size() + "= stories count");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
refreshDisplay();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Mystory story = stories.get(position);
Intent next = new Intent(this, ShowStory.class);
next.putExtra("thisstory", story);
startActivity(next);
}
public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
// ---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
public void refreshDisplay() {
Log.i(DBAdapter.TAG, stories.size() + "= storeis count");
ArrayAdapter<MyStory> adapter = new StoryAdapter(this, stories);
setListAdapter(adapter);
}
}
感谢
推荐答案
是的,你可以做的比较里面onItemClick日
yes, you can do compare the date inside onItemClick
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
if(Date compare)
{
// do nothing
}
else
{
MyStory story = stories.get(position);
Intent next = new Intent(this, ShowStory.class);
next.putExtra("thisstory", story);
startActivity(next);
}
}
这篇关于如何限制&QUOT; onListItemClick&QUOT;到时间范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文