我使用sax解析器成功解析了我的xml文件。我怀疑如何将字符串转换为文件路径。我有3个微调器,第一个微调器显示我的父节点字符串值,第二个微调器显示子节点名称标签值和第三个微调器显示路径标签值。这是我的xml文件链接请参阅此链接= http://paste.org/42924
我希望你现在清楚我正在尝试将我的路径标记字符串值转换为sdcard文件路径。我将路径标记字符串值存储在path_List数组列表中。现在我在这个数组列表中得到了所有路径字符串值。如何将这个sting值转换为文件路径?我希望以网格视图格式在同一屏幕底部显示图像。现在我将路径标记字符串值存储在我的数组列表中,数组列表名称是path_List。如何转换转换我的文件路径?
这是我的源代码:
public class ParxmlActivity extends Activity {
private String array_spinner[];
private Cursor cursor;
private int columnIndex;
ParsedExampleDataSet parsedExampleDataSet= null;
ArrayList<String> hltag_List=new ArrayList<String>();
ArrayList<Subchild> sltag_List=new ArrayList<Subchild>();
ArrayList<String> name_List = new ArrayList<String>();
ArrayList<String> path_List =new ArrayList<String>();
Spinner spinner_hltag,spinner_sltag, spinner_path;
ArrayAdapter<String> adapter_hltag;
ArrayAdapter<String> adapter_sltag;
ArrayAdapter<String> adapter_path;
int hltagPos = 0;
int sltagPos = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
spinner_hltag= (Spinner) findViewById(R.id.spinner1);
spinner_sltag = (Spinner) findViewById(R.id.spinner2);
spinner_path =(Spinner) findViewById(R.id.spinner3);
try {
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader */
ExampleHandler myExampleHandler = new ExampleHandler();
xr.setContentHandler(myExampleHandler);
/* Parse the xml-data from our file. */
xr.parse(new InputSource(getAssets().open("neevee.xml")));
/* Parsing has finished. */
parsedExampleDataSet =myExampleHandler. myParsedExampleDataSet;
for (int i = 0; i < parsedExampleDataSet.gethltag().size(); i++) {
Log.v("gethltag SIZE ", ""+parsedExampleDataSet.gethltag().size());
hltag_List.add(parsedExampleDataSet.getHLTag().get(i));
}
sltag_List = parsedExampleDataSet.getSLTag(hltag_List.get(hltagPos));
for(int i = 0; i < sltag_List.size(); i++) {
name_List.add(sltag_List.get(i).name);
path_List.add(sltag_List.get(i).path);
}
adapter_hltag = new ArrayAdapter<String>(ParxmlActivity.this,android.R.layout.simple_spinner_item, hltag_List);
spinner_hltag.setAdapter(adapter_hltag);
adapter_sltag = new ArrayAdapter<String>(ParxmlActivity.this,android.R.layout.simple_spinner_item, name_List);
spinner_sltag.setAdapter(adapter_sltag);
adapter_path = new ArrayAdapter<String>(ParxmlActivity.this,android.R.layout.simple_spinner_item, path_List);
spinner_path.setAdapter(adapter_path);
} catch (Exception e) {
}
}
}
答案 0 :(得分:1)
GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
sdcardImages.setAdapter(new ImageAdapter(this));
//创建一个名为ImageAdapter的新类,它扩展了BaseAdapter:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return path_List.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
//为适配器引用的每个项目创建一个新的ImageView
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
for (int i=0;i<path_List.size();i++){
Bitmap bitmap = BitmapFactory.decodeFile(path_List);
imageView.setImageBitmap(bitmap);
return imageView;
}
}