问题描述
我想建立在其中,当单击列表视图中的文件夹,将在相同的活动显示该文件夹中的文件列表的功能。即刷新不同的数据相同的列表视图。我已经建立像结构的目录数据库和得到他们的文件和文件夹列表。
I am trying to build a function in which when a folder is clicked in listview it would display the list of files inside that folder in the same activity . ie refreshing the same listview with different data. I have built a directory like structure in database and getting the list of files and folders from their.
public class SkydriveFolderList extends Activity
{
ArrayList<String> filelist1=new ArrayList<String>();
ArrayList<String> filepath=new ArrayList<String>();
ArrayList<String> isfolder=new ArrayList<String>();
ArrayList<Integer> fileid=new ArrayList<Integer>();
ListView lv;
EditText et;
ArrayAdapter<SearchResults> arrayAdapter;
Button back;
TextView path;![enter image description here][1]
public void onCreate(Bundle SkydriveFolderList)
{
Intent i = getIntent();
filelist1 = i.getStringArrayListExtra("FileList");
filepath = i.getStringArrayListExtra("FilePath");
isfolder = i.getStringArrayListExtra("isFolder");
fileid = i.getIntegerArrayListExtra("FileId");
super.onCreate(SkydriveFolderList);
ArrayList<SearchResults> searchResults = GetSearchResults();
setContentView(R.layout.filelist);
lv = (ListView)findViewById(R.id.skydrive_list);
et=(EditText)findViewById(R.id.inputSearch);
path=(TextView)findViewById(R.id.filepath);
back=(Button)findViewById(R.id.back);
arrayAdapter =new ArrayAdapter<SearchResults>(this,android.R.layout.simple_list_item_1,searchResults);
// ((ListView) arrayAdapter).setAdapter();
lv.setAdapter(new MyCustomBaseAdapter(this, searchResults));
//lv.setAdapter(arrayAdapter);
et.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)
{
// When user changed the Text
SkydriveFolderList.this.arrayAdapter.getFilter().filter(cs);
}
@Override
public void afterTextChanged(Editable arg0)
{
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3)
{
// TODO Auto-generated method stub
}
});
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Object o = parent.getItemAtPosition(position);
SearchResults fullObject = (SearchResults)o;
// prestationEco str=(prestationEco)o;//As you are using Default String Adapter
Toast.makeText(getBaseContext(),fullObject.getFilename(),Toast.LENGTH_SHORT).show();
}
});
}
请检查上面的链接,查看应用程序的快照。
Please check the above link to see the snapshot of the app.
现在在这,单击该文件夹时,列表视图应与该文件夹内的文件列表刷新。我应该怎么办呢?
Now in that,when the document folder is clicked , the listview should be refreshed with the list of files inside that folder. How should i do it ?
推荐答案
在列表视图用户点击insted的刷新整个列表视图可以调用的 adapter.notifyDataSetChanged()
这将刷新你的看法,没有任何延迟或崩溃....这将是you..Hope更好meathod这会有所帮助。
When the user click on the list view insted of refreshing the whole listview you can call adapter.notifyDataSetChanged()
this will refresh your view without any lag or crash....this will be a better meathod for you..Hope this will help.
这篇关于清爽的ListView在Android的新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!