在Android上使用TextView问题

|
import android.app.Activity;

import android.app.ListActivity;

import android.content.ActivityNotFoundException;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ListAdapter;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

import android.widget.AdapterView.OnItemClickListener;



public class textfile extends ListActivity {

   // private static final int PICKFILE_RESULT_CODE = 0;

                private List<String> items = null;

                private File currentDirectory;

                private ArrayAdapter<String> fileList;

                   Intent myIntent = null;

                /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        currentDirectory = new File(\"/sdcard/myfolder\");

        getFiles(currentDirectory.listFiles());

         setContentView(R.layout.main);



    }  



    protected void onListItemClick (AdapterView<?> parent, ListView l, View v, int position, long id)

    {

     int selectedRow = (int)id;



       currentDirectory = new File(items.get(selectedRow));

     if(currentDirectory.isDirectory()){

          getFiles(currentDirectory.listFiles());

     } else{

                  //if the selected file is not a directory. get the filename 

           currentDirectory.getPath();

     }

     Intent myIntent = null;



     if(((TextView) v).getText().equals(\"sdcard/myfolder/anskey.txt\")){

         myIntent = new Intent(v.getContext(), dialog.class);

        }





        startActivity(myIntent);

    }  



    private void getFiles(File[] files){

items = new ArrayList<String>();

     for(File file : files){

     items.add(file.getPath());



     }

       fileList = new ArrayAdapter<String>(this,R.layout.list_item, items);

        setListAdapter(fileList);



    }

}       
在此程序中,我以列表形式显示目录结构显示\“ sdcard / myfolder \”。 现在我要做的是,当我单击\“ sdcard / myfolder / anskey.txt \” dialog.class活动时应该打开。 除了单击\“ sdcard / myfolder / anskey.txt \”以外,dialog.class活动没有打开。     
已邀请:
据我所知,您的ѭ1签名不正确。它应该是:
protected void onListItemClick(ListView l, View v, int position, long id)
这是您要纠正的第一件事。您的代码可能还有其他问题。     
我没有看到您将Listener分配给listView,也没有看到您声明了要实现onListItemClickListener的类,因此onListItemListener的实现只是另一种方法。按照这个简单的教程来完成     

要回复问题请先登录注册