मैं एंड्रॉइड के लिए एक एप्लीकेशन कर रहा हूं और मुझे कुछ चाहिए जो यह है कि यह एसडी कार्ड में सभी फाइलों और निर्देशिकाओं की एक सूची दिखाता है और इसे विभिन्न निर्देशिकाओं के माध्यम से स्थानांतरित करने में सक्षम होना चाहिए। मुझे a good tutorial in anddev मिला। मैंने कुछ चीजों को संशोधित किया ताकि एप्लिकेशन एसडी कार्ड में चलता है न कि एंड्रॉइड रूट निर्देशिकाओं में, लेकिन शेष ज्यादातर समान होते हैं।लॉगकैट त्रुटि: "एडव्यू व्यू (व्यू, लेआउट पैराम्स) एडाप्टर व्यू में समर्थित नहीं है" एक सूची दृश्य
इस गतिविधि के लिए मेरे xml फ़ाइल है:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ListView>
और इस गतिविधि के लिए कोड है:
import hackreatorz.cifrador.R;
import java.io.File;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ArchivosSD extends ListActivity {
private ArrayList<String> directoryEntries = new ArrayList<String>();
private File currentDirectory = new File("/sdcard/");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
browseToSD();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
private void browseToSD() {
browseTo(new File("/sdcard/"));
}
private void upOneLevel() {
if(this.currentDirectory.getParent() != null)
this.browseTo(this.currentDirectory.getParentFile());
}
private void browseTo(final File directory) {
if (directory.isDirectory()) {
this.currentDirectory = directory;
fill(directory.listFiles());
} else {
Toast.makeText(ArchivosSD.this, this.directoryEntries.get(this.getSelectedItemPosition()), Toast.LENGTH_SHORT).show();
}
}
private void fill(File[] files) {
this.directoryEntries.clear();
this.directoryEntries.add(getString(R.string.current_dir));
if(this.currentDirectory.getParent() != null)
this.directoryEntries.add(getString(R.string.up_one_level));
int currentPathStringLength = (int) this.currentDirectory.getAbsoluteFile().length();
for (File file : files) {
this.directoryEntries.add(file.getAbsolutePath().substring(currentPathStringLength));
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.archivos_sd, this.directoryEntries));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
int selectionRowID = (int) this.getSelectedItemPosition();
String selectedFileString = this.directoryEntries.get(selectionRowID);
if (selectedFileString.equals(".")) {
this.browseToSD();
} else if(selectedFileString.equals("..")) {
this.upOneLevel();
} else {
File clickedFile = null;
clickedFile = new File(this.currentDirectory.getAbsolutePath() + this.directoryEntries.get(selectionRowID));
if(clickedFile != null)
this.browseTo(clickedFile);
}
}
}
मैं ग्रहण में किसी भी त्रुटि नहीं मिलता है, लेकिन मैं एक मिल मेरे फोन पर एप्लिकेशन चलाते समय बंद करें और जब मैं लॉगकैट को देखता हूं तो मुझे निम्नलिखित दिखाई देता है:
01-01 23: 30: 29.858: त्रुटि/एंड्रॉइड रनटाइम (14 9 11): मुख्य अपवाद: मुख्य 01-01 23: 30: 29.858: त्रुटि/AndroidRuntime (14911): java.lang.UnsupportedOperationException: addView (देखें, LayoutParams) AdapterView में
मैं करने के लिए एक सुराग क्या नहीं है समर्थित नहीं है करो, मैंने Google में देखा है और मुझे कुछ भी नहीं मिला और मैंने स्टैक ओवरफ्लो पर भी ऐसा किया। जावा में और एंड्रॉइड के लिए यह मेरा पहला एप्लीकेशन है, इसलिए मैं असली एन 00 बी हूं और अगर जवाब वहां था, तो मुझे समझ में नहीं आया, इसलिए अगर आप यह समझ सकें कि मुझे इस त्रुटि को ठीक करने के लिए क्या करना चाहिए और क्यों।
अग्रिम में सबकुछ के लिए धन्यवाद।
बढ़िया! यह आपको बहुत धन्यवाद देता है! मुझे आपके उत्तर के बारे में कोई संदेह है, "android.R.layout.simple_list_item_1" में क्या शामिल है? अगर मैं "android.R.layout.simple_list_item_1" का उपयोग करता हूं, तो लिस्टव्यू और टेक्स्टव्यू के साथ किए गए लेआउट के साथ क्या होता है? आपका बहुत बहुत धन्यवाद! –
जब आप एक ArrayAdapter बनाते हैं तो आप प्रत्येक सूची आइटम पर उपयोग किए जाने वाले लेआउट संसाधन को पास करते हैं (और ऐरेएडाप्टर केवल टेक्स्ट व्यू चाहता है)। लेआउट फ़ाइल जहां आप "स्क्रीन" सेट करते हैं, को सेटकंटेंट व्यू (R.layout.your_layout) के साथ, क्रेट के अंदर उपयोग किया जाना है। –
COuld I बदलते हैं "android.R.layout.simple_list_item_1" से R.layout.myxml अगर उस XML फ़ाइल में निम्न कोड था ?: Xml संस्करण = "1.0" एन्कोडिंग = "utf-8"?> \t –