gpt4 book ai didi

java - 将当前项目位置传递给内部类?

转载 作者:行者123 更新时间:2023-12-01 18:12:23 25 4
gpt4 key购买 nike

如何将当前 Hashmap 键位置传递给我的内部类?

我需要将 data.get(position) 传递给我的内部类 Click。通常我会宣布它是最终的,但我不知道在这种情况下这是如何完成的?

    public class UpcomingGridViewAdapter extends BaseAdapter {

public boolean pressedMovieItem;

Context context;
ArrayList<HashMap<String, String>> data;
HashMap<String, String> mylist = new HashMap<>();

public UpcomingGridViewAdapter(Context a, ArrayList<HashMap<String, String>> d) {
context = a;
data = d;
}

public int getCount() {
return data.size();
}

public HashMap<String, String> getItem(int position) {
return data.get(position);
}

public long getItemId(int position) {
return position;
}

public View getView(final int position, View convertView, ViewGroup parent) {

if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.upcoming_grid_item, parent, false);
}
final ImageView poster = (ImageView) convertView.findViewById(R.id.upcoming_image);




mylist = data.get(position);


final String posterPath = mylist.get("poster_path");


// set image url correctly
// sizes for image 45, 92, 154, 185, 300, 500
final String url = "http://image.tmdb.org/t/p/w185" + posterPath;


// load image url into poster
Picasso.with(context).load(url).into(poster);

// load image url into poster

// Get onclick of item and pass data to singleitemview for upcoming

convertView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {


// need to pass data.get(position) to the inner class click
new Click().execute();

}
});

return convertView;


}

// Downloading data asynchronously
class Click extends AsyncTask< Void, Void, Void> {

@Override
protected void onPreExecute() {

// TODO setup progressdialog

}

@Override
protected Void doInBackground(Void... params) {


mylist = data.get(position); // need to get position

Intent intent = new Intent(context, UpcomingSingleItem.class);

intent.putExtra("poster_path", mylist.get(Upcoming.TAG_POSTER));

intent.putExtra("title", mylist.get(Upcoming.TAG_TITLE));

intent.putExtra("release_date", mylist.get(Upcoming.TAG_RELEASE));

intent.putExtra("overview", mylist.get(Upcoming.TAG_OVERVIEW));

intent.putExtra("id", mylist.get(Upcoming.TAG_ID));

intent.putExtra("vote_average", mylist.get(Upcoming.TAG_VOTE_AVG));


context.startActivity(intent);


return null;
}


@Override
protected void onPostExecute(Void result) {

super.onPostExecute(result);

// TODO stop progressdialog
}

}

}

最佳答案

我认为您希望在 Click asynctask 中占据位置,以便在 asynctask 调用中传递您的位置:

new Click().execute(position);

然后使用如下参数接收它:

mylist = data.get(params[0]); // get position here which is passed 

关于java - 将当前项目位置传递给内部类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32006297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com