在我的应用程序中,我想更改列表视图文本颜色.在这种情况下,我使用XML文件进行列表视图.可能吗?如果是,那么举个例子.
gender.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/topelg"
>
<ListView
android:id="@+id/android:list"
android:layout_marginTop="60dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#000000"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Egender.java
package com.Elgifto;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
public class Egender extends ListActivity{
Button b1;
ListView lv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gender);
// b1=(Button) findViewById(R.id.butt1);
b1=new Button(this);
b1.setText("Done");
//b1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我动态获取字符串值 我想将这些值分配给字符串数组然后打印这些值.但它显示一个错误(空指针异常)EX:
String[] content = null;
for (int s = 0; s < lst.getLength(); s++) {
String st1 = null;
org.w3c.dom.Node nd = lst.item(s);
if (nd.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
NamedNodeMap nnm = nd.getAttributes();
for (int i = 0; i < 1; i++) {
st1 = ((org.w3c.dom.Node) nnm.item(i)).getNodeValue().toString();
}
}
content[s] = st1;
//HERE it shows null pointer Exception.
}
Run Code Online (Sandbox Code Playgroud)
谢谢
在我的应用程序中,当您单击时会出现一个按钮,将出现一个警报对话框.该警报对话框由单选列表项组成.这里我想设置单选项列表项的文本大小.可能吗?如果是的话怎么做
以下是我的代码
sclist.java
package com.examples.scl;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class sclist extends Activity {
private static final int DIALOG_SINGLE_CHOICE = 1;
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_SINGLE_CHOICE:
return new AlertDialog.Builder(sclist.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle("Single choice list")
.setSingleChoiceItems(R.array.select_dialog_items2, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked on a radio button do some stuff */
}
})
.setPositiveButton("ok", new DialogInterface.OnClickListener() …Run Code Online (Sandbox Code Playgroud)