自烤面包的android烤面包、android

2023-09-06 17:21:32 作者:你好特别

荫试图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()