【发布时间】:2014-04-23 09:26:20
【问题描述】:
当我使用此代码时:
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> a, View v, int position, long id)
{
String itemname = new Integer(position).toString(); <= this
Intent intent = new Intent();
intent.setClass(Spisok.this, Prob.class);
Bundle b = new Bundle();
b.putString("posit", itemname);
intent.putExtras(b);
startActivity(intent);
}
});
我有项目的位置,但我想获得 id。 这非常重要,因为在我的情况下它们并不相等。 帮我更正这段代码(标记线),我可以得到它(确切的ID)。
概率:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prob);
Bundle bundle = getIntent().getExtras();
String itemname = "n" + bundle.getString("posit");
Context context = getBaseContext();
String text = readRawTextFile(context, getResources().getIdentifier(itemname, "raw", "ru.ibir.irrveb"));
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.setBackgroundColor(0);
String summary = "<!Doctype html><html><head><meta charset=utf-8></head><body>" + text + "</body></html>";
myWebView.loadData(summary, "text/html", "utf-8");
}
public static String readRawTextFile(Context ctx, int resId)
{
InputStream inputStream = ctx.getResources().openRawResource(resId);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
StringBuilder text = new StringBuilder();
try {
while (( line = buffreader.readLine()) != null) {
text.append(line);
text.append('\n');
}
} catch (IOException e) {
return null;
}
return text.toString();
}
}
【问题讨论】:
标签: android list listview android-listview onitemclicklistener