本文介绍了自烤面包的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
荫试图changebackground和烤面包片的使用文本颜色在我的应用
LayoutInflater infator = getLayoutInflater();
查看布局= infator.inflate(R.layout.toast,(ViewGroup中)findViewById(R.id.toast_layout));
TextView的toastText =(TextView中)findViewById(R.id.toasttext);
toastText.setBackgroundColor(Color.YELLOW);
toastText.setText(UEI:+ o.getUei());
吐司面包=新吐司(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(布局);
toast.show();
这code是present在我的列表视图中OnItemClickListener。
但是,应用程序被力空指针异常!!
关闭这是什么abve的onclick监听器,它可以提供更好的图片。
公共无效的onCreate(最终捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.alarms);
m_alarmAdapter =新AlarmAdapter(这一点,R.layout.severity_item,m_alarms);
setListAdapter(m_alarmAdapter);
ListView的LV = getListView();
lv.setOnItemClickListener(新OnItemClickListener(){
公共无效onItemClick(最终适配器视图<>母公司,最终视图中查看,最终诠释的位置,最终长的id){
Log.d(TAG,点击+视图);
最后报警O = m_alarmAdapter.getItem(位置);
LayoutInflater infator = getLayoutInflater();
解决方案
你问你的当前视图来寻找 toasttext
的ID,而不是你刚才下载查看。尝试 layout.findViewById()
Iam trying to changebackground and text color of toast in my application using
LayoutInflater infator = getLayoutInflater();
View layout =infator.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout));
TextView toastText = (TextView) findViewById(R.id.toasttext);
toastText.setBackgroundColor(Color.YELLOW);
toastText.setText("uei:"+o.getUei());
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
This code is present in OnItemClickListener of my listview.
But the application gets force closed with null pointer exception!!
this is what abve the onclick listener, which could give a better picture.
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alarms);
m_alarmAdapter = new AlarmAdapter(this, R.layout.severity_item, m_alarms);
setListAdapter(m_alarmAdapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
Log.d(TAG, "clicked: " + view);
final Alarm o = m_alarmAdapter.getItem(position);
LayoutInflater infator = getLayoutInflater();
解决方案
You are asking your current view to look for the toasttext
id, not the View you just loaded. Try layout.findViewById()
这篇关于自烤面包的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!