gpt4 book ai didi

android ListView onItemClick

转载 作者:太空狗 更新时间:2023-10-29 13:23:28 27 4
gpt4 key购买 nike

每次我运行这个,我都会得到错误。我不知道怎么了?我只想通过索引从 array 中获取字符串并将其放在 URL 上并在另一个 Activity 中运行它。

包信息.androidhive.customlistviewvolley;

import java.util.ArrayList;

import com.squareup.picasso.Picasso;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.app.Activity;
import android.content.Intent;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

public class Show extends Activity {
ArrayList<String> lista = new ArrayList<String>();
ArrayAdapter<String> adaptera;
int po;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show);

ListView myListView = (ListView)findViewById(R.id.mylistView1);
myListView.setClickable(true);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent appInfo = new Intent(getApplicationContext(), VideoViewActivity.class);
ArrayList<String> dad =appInfo.getStringArrayListExtra("eps");
int itemPosition = position;
appInfo.putExtra("url",dad.get(itemPosition).toString());
startActivity(appInfo);
}
});



}

@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Intent i = getIntent();
String aaaaa = i.getStringExtra("img");
String tit = i.getStringExtra("rank");
TextView te = (TextView) findViewById(R.id.textView1);
te.setText(tit);
ArrayList<String> dad =i.getStringArrayListExtra("eps");
ImageView isd = (ImageView)findViewById(R.id.imageView1);
Picasso.with(getBaseContext()).load(aaaaa).into(isd);
ListView myListView = (ListView)findViewById(R.id.mylistView1);
ArrayList<String> myStringArray1 = new ArrayList<String>();
for (int f= 1; f <= dad.size();f++)
{
myStringArray1.add(String.valueOf(f));
}
adaptera = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myStringArray1);

adaptera.notifyDataSetChanged();
myListView.setAdapter(adaptera);
}


}

最佳答案

关于这段代码:

Intent appInfo = new Intent(getApplicationContext(), VideoViewActivity.class);
ArrayList<String> dad =appInfo.getStringArrayListExtra("eps");
int itemPosition = position;
appInfo.putExtra("url",dad.get(itemPosition).toString());
startActivity(appInfo);

变量 dadnull,因此 dad.get(itemPosition) 抛出 NullPointerException。

关于android ListView onItemClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25099440/

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