下面是我的列表視圖。數據從SD卡收集並列在列表中。但從SD卡檢索到的文件名以「.txt」結尾如何從列出的文件名中刪除「.txt」?
mainListView = (ListView) getActivity().findViewById(R.id.mainListView);
myList = new ArrayList<String>();
File sdCard = Environment.getExternalStorageDirectory();
file = new File(sdCard.getAbsolutePath() + "/St/") ;
File list[] = file.listFiles();
for(int i=0; i< list.length; i++)
{
myList.add(list[i].getName());
}
listAdapter = new ArrayAdapter<String>(getActivity(),R.layout.simplerow, myList);
mainListView.setAdapter(listAdapter);
mainListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String textToPass = myList.get(position);
Intent i = new Intent(getActivity(), ViewActivity.class);
i.putExtra("textToPass", textToPass);
startActivity(i);
}
});
不是它解決了這裏http://stackoverflow.com/q/14018950/1626878 –