首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse无法看到我的列表视图的自定义布局

Eclipse无法看到我的列表视图的自定义布局
EN

Stack Overflow用户
提问于 2012-12-09 13:41:48
回答 1查看 577关注 0票数 0

刚开始时,我是安卓和Java编程的新手,但我对C,C++,Perl,PerlTk,OpenGL,Pascal,微控制器编程(C,汇编)等编程语言有丰富的经验.我做了一项研究,我尝试了很多东西,但没有任何帮助。

所以我想改变我的列表视图中的字体大小和字体颜色。我找到了两个解决方案:

  1. 破门而入。这是可行的,但如果我修改我的风格比我必须修改所有其他元素,什么是从这种风格。所以没有,如果我选择这个方法,我仍然不能修改列表视图按下而不是按下状态背景色。
  2. 定制布局。我更喜欢这种方法,但是如果我引用布局,则eclipse会说:“无法解析,或者不是字段”。

我的代码:

代码语言:javascript
复制
public class Btcall extends Activity 
{
  private ListView list;
  final int REQUEST_ENABLE_BT = 1;
  TextView kiirni;
  TextView scanned;
  View view2;
  View view3;
  Button connectbutton;
  private ArrayAdapter<String> founddevices = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_btcall);
    view2=(View) findViewById(R.id.view2);
    view3=(View) findViewById(R.id.view3);
    connectbutton=(Button) findViewById(R.id.button1);
    kiirni=(TextView)findViewById(R.id.text1);
    scanned=(TextView)findViewById(R.id.scanned);
    list = (ListView) findViewById(R.id.list1);
  }

  public void irddki(View v) 
  {
    BluetoothAdapter bluetooth = null;
    BroadcastReceiver mReceiver = null;
    bluetooth = BluetoothAdapter.getDefaultAdapter();
    founddevices = null;
    if(bluetooth != null)
    {
      String status;
      if (bluetooth.isEnabled()) 
      {
        String mydeviceaddress = bluetooth.getAddress();
        String mydevicename = bluetooth.getName();
        status = mydevicename + " : " + mydeviceaddress;
        Toast.makeText(this, status, Toast.LENGTH_LONG).show();

        bluetooth.startDiscovery(); 
        mReceiver = new BroadcastReceiver() 
        {
          public void onReceive(Context context, Intent intent) 
          {
            String action = intent.getAction();

            if (BluetoothDevice.ACTION_FOUND.equals(action)) 
            {
              BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

              founddevices.add(device.getName() + "\n" + device.getAddress());
            }
          }
        };
        scanned.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.setMargins(470, 270, 0, 0);
        connectbutton.setLayoutParams(lp);
        connectbutton.setText("Scan again");
        kiirni.setVisibility(View.GONE);
        list.setBackgroundResource(R.color.Lightgrayy);
        list.setVisibility(View.VISIBLE);

        view2.setVisibility(View.VISIBLE);
        view3.setVisibility(View.VISIBLE);
        /*HERE IS THE PROBLEM--->*/
        founddevices = new ArrayAdapter<String>(this, android.R.layout.mylist);
        list = (ListView) findViewById(R.id.list1);
        list.setAdapter(founddevices);

        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
        registerReceiver(mReceiver, filter);
      }
      else
      {
        if (!bluetooth.isEnabled()) 
        {
          Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
          startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        }
      }
    }
  }

  public void close(View v) 
  {
    moveTaskToBack(true);
  }
}

我写了一个立方体布局,我把它放在布局文件夹,它也在R文件夹中。

但是Eclipse看不到它..。也许我得进口些什么?我相信这是一个问题,但我会感激的答案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-09 14:13:25

试着使用以下方法:

代码语言:javascript
复制
R.layout.mylist

而不是:

代码语言:javascript
复制
android.R.layout.mylist
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13787914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档