Hai Friends我是Android的新手..如何从ArrayAdapter类导航到另一个活动class.i不知道如何导航。我知道“intent”关键字用于将一个活动导航到另一个活动..但是现在我正在使用ArrayAdapter类,如果我使用“intent”关键字来导航另一个活动,我会收到错误。
package org.ajsquare.test;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class Teamname extends ArrayAdapter<String>
{
private LayoutInflater mInflater;
private String[] mStrings;
private TypedArray mimages;
String mteam=null;
private int mViewResourceId;
Context c;
public Teamname(Context context, int textViewResourceId,TypedArray images,String[] test) {
super(context, textViewResourceId,test);
c=context;
mimages=images;
mViewResourceId=textViewResourceId;
mInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mStrings=test;
}
public int getCount()
{
return mStrings.length;
}
public String getId(int position)
{
return mStrings[position];
}
public long getItemId(int position)
{
return 0;
}
public View getView(final int position, View convertview, ViewGroup parent)
{
convertview=mInflater.inflate(mViewResourceId, null);
ImageView imageView=(ImageView)convertview.findViewById(R.id.image_teamname);
imageView.setImageDrawable(mimages.getDrawable(position));
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println(position);
//Intent intent=new Intent(Teamname.this,Team_details.class);// i am getting error from this line
//startActivity(this);
}
});
return convertview;
}
}
//我不能在这个类中使用意图..请给出解决方案
答案 0 :(得分:5)
如果您的课程为NonActivityClass
,请使用context
开始新的活动....
Intent intent=new Intent(c,Team_details.class);
c.startActivity(intent);
答案 1 :(得分:0)
Intent intent=new Intent(Teamname.this,Team_details.class);
startActivity(this);
使用此代码并尝试::::
Intent intent=new Intent(Teamname.this,Team_details.class);
startActivity(intent);