import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import com.nusecond.suredeal.app.R;
import com.nusecond.suredeal.app.suredeal.adapter.CustomAdapter;
import com.nusecond.suredeal.app.suredeal.adapter.CustomPromoAdapter;
import java.util.ArrayList;
public class Promo extends AppCompatActivity {
GridView gv;
Context context;
ArrayList programName;
public static String[] programNameList={"AppleMacBook","HP_note_Book","LG_NEXUS","NokiaLumia","SamsungRT","SONY_BRAVIA","Sansui"};
public static int [] programImages={R.drawable.apple,R.drawable.hp,R.drawable.nexus,R.drawable.lumia,R.drawable.fridge,R.drawable.tv,R.drawable.tv1};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv=(GridView)findViewById(R.id.gridView1);
//gv.setAdapter(new CustomPromoAdapter(this,programNameList,programImages));
gv.setAdapter(new CustomPromoAdapter(this,programNameList,programImages));
}
}
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.nusecond.suredeal.app.R;
import com.nusecond.suredeal.app.suredeal.activity.MainActivity;
import com.nusecond.suredeal.app.suredeal.activity.Promo;
/**
* Created by ns2 on 2/4/16.
*/
public class CustomPromoAdapter extends BaseAdapter{
ImageView imageView;
TextView textView;
String [] result;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomPromoAdapter(Promo promo, String[] programNameList, int[] programImages) {
// TODO Auto-generated constructor stub
result=programNameList;
context=promo;
imageId=programImages;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return result.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
view=inflater.inflate(R.layout.promo_gridlist,null);
textView=(TextView)view.findViewById(R.id.textView1);
imageView=(ImageView)view.findViewById(R.id.imageView1);
imageView.setImageResource(imageId[position]);
textView.setText(imageId[position]);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "You Clicked " + result[position], Toast.LENGTH_LONG).show();
}
});
return view;
}
}
试试这个,
CustomPromoAdapter adapter = new CustomPromoAdapter(this,programNameList,programImages)
gv.setAdapter(adapter);
问题内容: 我正在尝试获取一些信息,但我的应用程序崩溃并显示以下消息: 这是代码: 这是一个纯课。的哪个调用不包含this 。我做错了吗?应始终位于内吗? 根据要求整体: 问题答案: 改成 您为布局充气。视图属于膨胀的布局。因此,使用view对象在中初始化视图 片段由活动主持 您可以在视图中使用和初始化 还在中初始化TextView 。由于Asynctask是一个内部类,因此您可以在那里更新ui
当我运行我的应用程序时,我有一个异常显示,所以我想帮助我:)异常是:java。lang.NullPointerException:尝试调用虚拟方法“int java”。lang.String。空对象引用上的长度() 当我单击Login类中的dd1按钮和按钮实现(public void getData(View v))方法时,会显示异常 非常感谢。 登录类 HttpManager类 日志:
问题内容: Process: com.example.vicevirus.myapplication, PID: 13471 java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String com.google.firebase.auth.FirebaseUser.getUid()’ on a n
在为我的CardView设置onclick listner时获得Nullpointer异常。 错误为: 原因:java.lang.NullPointerException:试图对com.jaysurya.project_scrollwithTap.mainactivity.onCreate(mainactivity.java:27)处的空对象引用调用虚拟方法“void android.suppor
每当我尝试使用firebase auth注册用户时,我的应用程序就会崩溃。我的代码如下: