===編集する===
このような何かが働いていない理由はありますか?それはうまくいかないと思うが動作しないlView.getChildCount()はリストにたくさんあり、強制的に閉じる
for (int i = 0; i < lView.getChildCount(); i++) {
ImageView imageView = (ImageView) lView.getChildAt(i).findViewById(R.id.listIcon);
imageView.setImageResource(R.drawable.someIcon);
}
====================
まず、私はあなたがカスタムアダプターを作ることができることを知っています。これは単純なファイルブラウザーなので何も進んでいないかもしれません。
とにかく私は私が書いているアプリの一部のための非常に単純なファイルブラウザで作業していると言ったように。私はディレクトリ内のすべてのファイルを表示し、その隣にアイコンを表示するように設定しました。今のアイコンは各ファイルで同じですが、私はファイルの各タイプ(すなわち、zip、フォルダ、スクリプトなど)のアイコンを持っていたいと思います。
私は何をしたいのですが、配列の後にすべてのものが作られているのですが、それぞれのポジションをチェックしてアイテムをチェックし、終わったら.zipアイコンをこの行の何かに変更します
for(eachposition){
if(position.endsWith(".zip"){
ImageView iv = (ImageView) findViewById(R.id.listIcon);
iv.setImageResource(R.drawable.zipImage);
}else if(position.endsWith(".sh"){
ImageView iv = (ImageView) findViewById(R.id.listIcon);
iv.setImageResource(R.drawable.scriptImage);
}else{
ImageView iv = (ImageView) findViewById(R.id.listIcon);
iv.setImageResource(R.drawable.generalImage);
}
}
とにかくここに私が現在使用しているコードがあります。これが必要な場合に備えて、どんなヘルプや入力にも感謝します
public class SampleList extends ListActivity {
private List item = null;
private List path = null;
private String root = "/sdcard/somefolder/";
private String current = null;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
context = getApplicationContext();
try{
getDir(root);
File directory = new File(root);
File[] contents = directory.listFiles();
if (contents.length == 0) {
TextView t = new TextView(this);
t=(TextView)findViewById(R.id.empty);
t.setText(R.string.emptyFol);
}
}catch (Exception e) {
Toast.makeText(NandPicker.this, R.string.nMount, Toast.LENGTH_LONG).show();
}
}
private void getDir(String dirPath){
item = new ArrayList();
path = new ArrayList();
File f = new File(dirPath);
File[] files = f.listFiles();
for(int i=0; i < files.length; i++){
File file = files[i];
//Problem was adding the path without the /
//path.add(file.getPath());
if(file.isDirectory()){
path.add(file.getPath()+"/");
item.add(file.getName() + "/");
}else{
path.add(file.getPath());
item.add(file.getName());
}
}
current = dirPath;
ArrayAdapter fileList = new ArrayAdapter(this, R.layout.row, R.id.rowTextView, item);
setListAdapter(fileList);
class IgnoreCaseComparator implements Comparator {
public int compare(String strA, String strB) {
return strA.compareToIgnoreCase(strB);
}
}
IgnoreCaseComparator icc = new IgnoreCaseComparator();
java.util.Collections.sort(path,icc);
java.util.Collections.sort(item,icc);
}
@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {
}
}