Eclipse可以';我看不到listview的自定义布局 开始时,我是Android和java编程中的新手,但我有很多编程语言,如C、C++、Perl、PerlTk、OpenGL、Pascal、微控制器编程(C、汇编)等。我做了一项研究,做了很多尝试,但都没有效果

Eclipse可以';我看不到listview的自定义布局 开始时,我是Android和java编程中的新手,但我有很多编程语言,如C、C++、Perl、PerlTk、OpenGL、Pascal、微控制器编程(C、汇编)等。我做了一项研究,做了很多尝试,但都没有效果,java,android,eclipse,listview,layout,Java,Android,Eclipse,Listview,Layout,因此,我想更改listview中的字体大小和字体颜色。 我找到了两种解决方案: 改变风格。这是可行的,但是如果我修改了我的样式,那么我就必须修改所有其他元素,从这个样式生成什么呢。所以不,如果我选择这种方法,我仍然无法修改listview的已按下和未按下状态背景色 自定义布局。我更喜欢这种方法,但是如果我参考布局,eclipse会说:“无法解析,或者不是字段” 我的代码: public class Btcall extends Activity { private ListView lis

因此,我想更改listview中的字体大小和字体颜色。 我找到了两种解决方案:

  • 改变风格。这是可行的,但是如果我修改了我的样式,那么我就必须修改所有其他元素,从这个样式生成什么呢。所以不,如果我选择这种方法,我仍然无法修改listview的已按下和未按下状态背景色

  • 自定义布局。我更喜欢这种方法,但是如果我参考布局,eclipse会说:“无法解析,或者不是字段”

  • 我的代码:

    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);
      }
    }
    
    公共类Btcall扩展活动
    {
    私有列表视图列表;
    最终整数请求\启用\ BT=1;
    文本视图基尔尼;
    文本视图扫描;
    视图2;
    视图3;
    按钮连接按钮;
    专用ArrayAdapter founddevices=null;
    @凌驾
    创建时受保护的void(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_btcall);
    view2=(视图)findViewById(R.id.view2);
    view3=(视图)findViewById(R.id.view3);
    connectbutton=(按钮)findViewById(R.id.button1);
    kiirni=(TextView)findViewById(R.id.text1);
    扫描=(TextView)findViewById(R.id.scanned);
    列表=(ListView)findViewById(R.id.list1);
    }
    DKI公共区域(视图五)
    {
    蓝牙适配器蓝牙=空;
    BroadcastReceiver mReceiver=null;
    bluetooth=BluetoothAdapter.getDefaultAdapter();
    founddevices=null;
    如果(蓝牙!=null)
    {
    字符串状态;
    如果(bluetooth.isEnabled())
    {
    字符串mydeviceaddress=bluetooth.getAddress();
    字符串mydevicename=bluetooth.getName();
    状态=mydevicename+”:“+mydeviceaddress;
    Toast.makeText(this,status,Toast.LENGTH_LONG).show();
    bluetooth.startDiscovery();
    mReceiver=新广播接收器()
    {
    公共void onReceive(上下文、意图)
    {
    String action=intent.getAction();
    if(BluetoothDevice.ACTION_FOUND.equals(ACTION))
    {
    BluetoothDevice=intent.getParcelableExtra(BluetoothDevice.EXTRA\u设备);
    添加(device.getName()+“\n”+device.getAddress());
    }
    }
    };
    扫描。设置可见性(视图。可见);
    RelativeLayout.LayoutParams lp=新的RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_内容,RelativeLayout.LayoutParams.WRAP_内容);
    lp.设定利润率(470270,0,0);
    connectbutton.setLayoutParams(lp);
    connectbutton.setText(“再次扫描”);
    kiirni.setVisibility(View.GONE);
    列表.setBackgroundResource(R.color.浅灰色);
    list.setVisibility(View.VISIBLE);
    view2.setVisibility(View.VISIBLE);
    view3.setVisibility(View.VISIBLE);
    /*这就是问题所在--->*/
    founddevices=new ArrayAdapter(这是android.R.layout.mylist);
    列表=(ListView)findViewById(R.id.list1);
    列表.setAdapter(founddevices);
    IntentFilter筛选器=新的IntentFilter(BluetoothDevice.ACTION\u已找到);
    registerReceiver(mrReceiver,过滤器);
    }
    其他的
    {
    如果(!bluetooth.isEnabled())
    {
    Intent enablebintent=新意图(BluetoothAdapter.ACTION\u REQUEST\u ENABLE);
    startActivityForResult(启用BTIntent、请求\启用\ BT);
    }
    }
    }
    }
    公共空间关闭(视图五)
    {
    moveTaskToBack(真);
    }
    }
    
    我写了一个custum布局,我把它放在layouts文件夹中,它也在R文件夹中

    但月食还是看不见它。。。也许我得进口点什么?我确信这是一个noob Q,但我会很感激您的回答。

    尝试使用以下方法:

    R.layout.mylist
    
    而不是:

    android.R.layout.mylist
    

    是的,我知道答案是这样的。。。谢谢你,雷纳德!改变使用eclipse右键单击中的布局样式