我需要在listView中打开frameLayout细节,但是当我按下buttonDetails时,它会打开一个错误的frameLayout。
这是我的adapterView的代码
public class SitesAdapter extends ArrayAdapter<AtlantisSite> {
ImageLoader imageLoader;
DisplayImageOptions options;
FrameLayout frameLayout;
public SitesAdapter(Context ctx, int textViewResourceId, List<AtlantisSite> sites) {
super(ctx, textViewResourceId, sites);
//Setup the ImageLoader, we'll use this to display our images
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(ctx).build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
//Setup options for ImageLoader so it will handle caching for us.
options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
}
/*
* (non-Javadoc)
* @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
*
* This method is responsible for creating row views out of a AtlantisSite object that can be put
* into our ListView
*/
@Override
public View getView(final int pos, final View convertView, final ViewGroup parent){
RelativeLayout row = (RelativeLayout)convertView;
Log.i("AtlantisSites", "getView pos = " + pos);
//ViewHolder mainViewHolder = null;
final ViewHolder viewHolder;
if(null == row){
//No recycled View, we have to inflate one.
LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = (RelativeLayout)inflater.inflate(R.layout.row_site, null);
viewHolder = new ViewHolder();
viewHolder.btnDownload = (Button) row.findViewById(R.id.btnDownload);
viewHolder.btnDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer pos=(Integer)v.getTag();
Log.i("AtlantisSites", "getView pos = " + pos);
//String url = getItem(pos).getLink();
DownloadZip zipActivity = new DownloadZip();
zipActivity.DownloadFromUrlZip();
//Intent i = new Intent(Intent.ACTION_VIEW);
//i.setData(Uri.parse(url));
//Intent zipActivity = new DownloadZip();
//zipActivity.start...;
//Toast.makeText(getContext(), "Downloading " + pos, Toast.LENGTH_SHORT).show();
}
});
viewHolder.btnDetails = (Button) row.findViewById(R.id.btnDetails);
viewHolder.btnDetails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Integer pos = (Integer) v.getTag();
//Log.i("AtlantisSites", "getView pos = " + pos);
getItemId(pos);
if(frameLayout.getVisibility()==View.GONE){
showFrameLayout();
} else {
hideFrameLayout();
}
}
});
row.setTag(viewHolder);
} else{
viewHolder = (ViewHolder) row.getTag();
}
//Get our View References
final ImageView iconImg = (ImageView)row.findViewById(R.id.iconImg);
TextView nameTxt = (TextView)row.findViewById(R.id.nameTxt);
TextView titleTxt = (TextView)row.findViewById(R.id.titleTxt);
//Button btnDownload = (Button)row.findViewById(R.id.btnDownload);
TextView summaryIta = (TextView)row.findViewById(R.id.textViewSummaryItaRow);
TextView summaryEng = (TextView)row.findViewById(R.id.textViewSummaryEngRow);
TextView priceItaTxt=(TextView)row.findViewById(R.id.txtViewPriceIta);
TextView priceEngTxt=(TextView)row.findViewById(R.id.txtViewPriceEng);
final ProgressBar indicator = (ProgressBar)row.findViewById(R.id.progress);
frameLayout = (FrameLayout)row.findViewById(R.id.frame_layout_listview);
//Set the relavent text in our TextViews
nameTxt.setText(getItem(pos).getName());
titleTxt.setText(getItem(pos).getTitle());
summaryIta.setText(getItem(pos).getSummaryIta());
summaryEng.setText(getItem(pos).getSummaryEng());
viewHolder.btnDetails.setTag(pos);
return row;
}
public class ViewHolder{
Button btnDownload;
Button btnDetails;
}
private void showFrameLayout(){
frameLayout = (FrameLayout) frameLayout.findViewById(R.id.frame_layout_listview);
frameLayout.setVisibility(View.VISIBLE);
}
private void hideFrameLayout(){
frameLayout = (FrameLayout) frameLayout.findViewById(R.id.frame_layout_listview);
frameLayout.setVisibility(View.GONE);
}
}
这个职位出了点问题。 请帮我找到错误解决方案。 感谢
答案 0 :(得分:0)
在方法showFrameLayout()中你没有任何对你想要显示的当前帧布局的引用,删除方法show / hide frameLayout和在监听器内部的详细信息btn
viewHolder.btnDetails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Integer pos = (Integer) v.getTag();
//Log.i("AtlantisSites", "getView pos = " + pos);
getItemId(pos);
FrameLayout detailsFrame = row.findViewById(R.id.frame_layout_listview);
if(detailsFrame.getVisibility()==View.GONE){
detailsFrame.setVisibility(View.VISIBLE);
} else {
detailsFrame.setVisibility(View.GONE);
}
}
});
作为一般建议,我将把我的FrameLayout放在视图中,这对于它来说是什么。
答案 1 :(得分:0)
我找到了解决方案。我必须声明Frame Layout final。它的工作原理
final FrameLayout detailsFrame =(FrameLayout)row.findViewById(R.id.frame_layout_listview);