每次我运行这个,我都会出错。我不知道怎么了?
我只想通过索引从array
获取字符串,并将其放到url上,然后在另一个活动中运行它。
包信息.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);
变量
dad
是null
,因此dad.get(itemPosition)
抛出一个nullpointerexception。关于android - android listview onItemClick,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25099440/