Hie Friends。
通过CustomAdapter存储图像大拇指的列表视图。
一个预览按钮,它不属于listview。
当用户选择listView的Image-Thumb时,新的Activity应该使用所选Thumb的URL打开。
我从JSON解析图像和拇指。
任何人都可以帮助我,我该怎么做?
public class ECard_main extends Activity
{
String catagories;
String anim_id,album_id,anim_name,anim_thumb,anim_url;
int global_position;
String anim_url_pass;
ImageView btnpreview;
TextView title;
public static boolean isQuit = false;
HorizontalListView hlv;
ArrayList<HashMap<String, String>> albumList;
@Override
protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.ecard_main);
btnpreview=(ImageView)findViewById(R.id.iv_preview);
title.setText(catagories);
hlv = (HorizontalListView)findViewById(R.id.listData);
albumList = new ArrayList<HashMap<String, String>>();
hlv.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "POSITION: "+position,Toast.LENGTH_SHORT).show();
btnpreview.setTag(position);
global_position=position;
}
}
);
AsycLove().execute();
}
public void onClick_preview(View v)
{
Intent i=new Intent(ECard_main.this,Preview.class);
Toast.makeText(getApplicationContext(),"Position in Preview::"+global_position,Toast.LENGTH_SHORT).show();
i.putExtra("Catagories", catagories);
i.putExtra("Web_Url", anim_url);
startActivity(i);
}
class AsycLove extends AsyncTask<String, String, String>
{
ProgressDialog progressDialog;
@Override
protected void onPreExecute()
{
super.onPreExecute();
progressDialog = new ProgressDialog(ECard_main.this);
progressDialog.setTitle("Loading");
progressDialog.setMessage("Please wait");
}
@Override
protected String doInBackground(String... aurl)
{
try
{
HttpPost postMethod = new HttpPost("http://demo1.idevtechnolabs.com/smartecard/love.php");
BufferedReader bufferedReader = null;
HttpClient client = new DefaultHttpClient();
HttpResponse response = null;
response = client.execute(postMethod);
final int statusCode = response.getStatusLine().getStatusCode();
bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer stringBuffer = new StringBuffer("");
String line = "";
String LineSeparator = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null)
{
stringBuffer.append(line + LineSeparator);
}
bufferedReader.close();
//-------------CONVERT DATA TO JSON---------------------------------
try
{
String myjsonstring = stringBuffer.toString();
JSONArray jsonArray = new JSONArray(myjsonstring);
JSONObject jsonObj = null;
albumList.clear();
jsonObj = jsonArray.getJSONObject(0);
for(int i=0; i<jsonArray.length();i++)
{
jsonObj = jsonArray.getJSONObject(i);
anim_id = jsonObj.getString("animation_id");
album_id = jsonObj.getString("album_id");
anim_name = jsonObj.getString("animation_name");
anim_thumb= jsonObj.getString("animation_thumb");
anim_url = jsonObj.getString("animation_url");
anim_url=anim_url.replaceAll("\"","");
HashMap<String, String> tmp_album = new HashMap<String, String>();
tmp_album.put("anim_id", anim_id);
tmp_album.put("anim_thumb", anim_thumb);
tmp_album.put("anim_url",anim_url);
albumList.add(tmp_album);
Log.v("Animation URL Position","Animation::"+global_position+"::"+anim_url);
}
}
catch (Exception e)
{
Log.v("Home ::","Call JSON Exception in get Album in List--->"+e.toString());
e.printStackTrace();
}
}
catch (IOException e)
{
Log.v("Exception: Get get Album in List","Name-"+e.toString());
e.printStackTrace();
}
return "0";
}
@Override
protected void onPostExecute(String code)
{
Toast.makeText(getApplicationContext(), "Image URL Call Successfully", Toast.LENGTH_LONG).show();
Log.v("Album","Album List::"+albumList);
ECard_main_Custom_Adapter adapter =new ECard_main_Custom_Adapter(getApplicationContext(),albumList,ECard_main.this);
hlv.setAdapter(adapter);
progressDialog.dismiss();
progressDialog = null;
}
}
}
请告诉我我在哪里做错了,我怎样才能得到解决方案?
谢谢
答案 0 :(得分:2)
最后我得到了解决方案:
public void onClick_preview(View v)
{
for(int p=0;p<=albumList.size();p++)
{
String animation_id=albumList.get(p).get("anim_id");
if(Integer.parseInt(animation_id)==global_position)
{
animation_url=albumList.get(p).get("anim_url");
break;
}
}
Intent i=new Intent(ECard_main.this,Preview.class);
i.putExtra("Catagories", catagories);
i.putExtra("Web_Url", animation_url);
startActivity(i);
}
答案 1 :(得分:1)
hlv = (HorizontalListView)findViewById(R.id.listData);
btnpreview=(ImageView)hlv.findViewById(R.id.iv_preview);
title.setText(catagories);
如果您的按钮位于列表项中,则需要像这样初始化按钮
答案 2 :(得分:0)
hlv.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "POSITION: "YourArrayList.get(position).get("your_image_url_tag");+,Toast.LENGTH_SHORT).show();
btnpreview.setTag(position);
global_position=position;
}
}
);