我有一個問題可能很簡單,但我不明白我在做什麼錯。我有一個列表視圖,作爲文件瀏覽器加載。這是我點擊任何項目時應該發生的事情。列表視圖OnItemClickListener無法正常工作?
protected void onListItemClick(ListView l, View v, int position, long id) {
File file = new File(path.get(position));
if (file.isDirectory())
{
if(file.canRead())
getDir(path.get(position));
else
{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
else
{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "]")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
但是,當我點擊的項目,沒有任何反應。我甚至檢查logcat,看看是否有任何活動,當我點擊,但絕對沒有。我是否需要以某種方式將此偵聽器鏈接到我的特定列表視圖?此外,如果我需要發佈更多信息,請讓我知道。非常感謝您的幫助!
新的問題
AlertDialog show = new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
else
{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "]")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
在這兩個,即時得到一個錯誤的alertDialog是不確定的。
什麼是你得到的確切的錯誤信息?什麼時候?在運行期間還是在編譯期間我在代碼中的任何地方都看不到alertDialog。你的意思是AlertDialog?如果是這樣,你可能忘記把它導入你的源文件嗎? – haffax