如何以 SD 卡为资源为列表视图中的每一行设置缩略图?
我想为 SD 卡中的每个相应行设置缩略图。到目前为止,我正在从 SD 卡获取列表视图。这是我的完整代码
public class SaveList extends ListActivity {
private List<String> item = null;
private List<String> path = null;
private String root="/sdcard/Photos/";
private TextView myPath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.savelist);
}
private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.savelistrow, item);
setListAdapter(fileList);
}
@Override
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.icon)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
else
{
final String path1= ("/sdcard/Photos/"+file.getName());
Intent intent = new Intent( getBaseContext(),FullView.class);
intent.putExtra("link",path1);
startActivity( intent);
}
}
}
请告诉我如何从 SD 卡添加正确的相应缩略图作为资源。我已经从静态图像中尝试过,但无法对动态资源执行此操作。非常感谢。
I would like to set a thumbnail picture for each corresponding row from the sd card.As of now I am getting the list view from the sd card.Here is the completed code of mine
public class SaveList extends ListActivity {
private List<String> item = null;
private List<String> path = null;
private String root="/sdcard/Photos/";
private TextView myPath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.savelist);
}
private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.savelistrow, item);
setListAdapter(fileList);
}
@Override
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.icon)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
else
{
final String path1= ("/sdcard/Photos/"+file.getName());
Intent intent = new Intent( getBaseContext(),FullView.class);
intent.putExtra("link",path1);
startActivity( intent);
}
}
}
Please tell me how to add right corresponding thumbnail from sd card as resource.I have tried it from static images but I am unable to do it for dynamic resource.Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我对你问题的理解,你想从 sdCard 加载图像,对吗?如果是这种情况,您可以这样做:
其次,您可以通过重写 getView() 制作自定义适配器来设置 ListView 中每行的缩略图,例如
According to my understanding of your question, you want to load an image from sdCard, right? If this is the case you can do it like this:
Secondly, you can set the thumbnail of each row in ListView by making a custom Adapter by overriding the getView() e.g.