に動作していないandroid.whyで2列のリストビューを作成したいこれは私の主な活動私はそれが
public class MainActivity extends AppCompatActivity {
//private static Button buttonPst;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent I = new Intent();
I.setAction("android.amila.action.PST");
startActivity(I);
}
}
);
}
}
Custom_row
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rowTitle"
android:layout_weight="1"
android:textSize="18sp"
android:typeface="normal" />
<TextView
android:text="@string/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rowSubtitle"
android:layout_weight="1"
android:textSize="18sp" />
ですこれはXMLファイルです
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_pst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.amila.newglossary.pst"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="@+id/pstList" />
.javaファイル
public class pst extends Activity {
String[] englishName = new String[]{"bacon", "Ham", "Tuna", "Candy", "Meatball", "Potato"};
String[] sinhalaName = new String[]{"wdddbhha", "wdddbhha", "wdddbhha", "wdddbhha", "wa", "wa"};
// Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_pst);
ListView listView = (ListView) findViewById(R.id.pstList);
adapter ada= new adapter(this,englishName,sinhalaName);
listView.setAdapter(ada);
}
}
これは、私は非常にこれを試してみましたし、最初の画面(メイン活動)が実行されているアダプタクラス
public class adapter extends ArrayAdapter<String> {
String[] englishName;
String[] sinhalaName;
Context c;
LayoutInflater inflater;
public adapter(Context context, String[] englishName,String[] sinhalaName) {
super(context, R.layout.custom_row,englishName);
this.c=context;
this.englishName=englishName;
this.sinhalaName=sinhalaName;
}
public class ViewHolder{
TextView englishTv;
TextView sinhalaTv;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
inflater = (LayoutInflater)
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.custom_row, null);
}
final ViewHolder holder=new ViewHolder();
holder.englishTv=(TextView)convertView.findViewById(R.id.rowTitle);
holder.sinhalaTv=(TextView)convertView.findViewById(R.id.rowSubtitle);
holder.englishTv.setText(englishName[position]);
holder.sinhalaTv.setText(sinhalaName[position]);
return super.getView(position, convertView, parent);
}
}
ですPSTを押してもエラーは発生せず、リストビューのウィンドウは表示されません。このエラーは、RUNに表示され、アプリ
E/AndroidRuntimeを閉じ:致命的な例外:メイン プロセス:com.example.amila.newglossary、PID:6309 java.lang.RuntimeException:活性ComponentInfoを{開始できませんcom.example.amila.newglossary/com.example.amila.newglossary.pst}: java.lang.RuntimeException:あなたのコンテンツには、IDが の属性が 'android.R.id.list' androidにあるListViewが必要です。 app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) android.app.ActivityThread.-wrap12(Acti vityThread.java)android.os.Looper.loopでandroid.os.Handler.dispatchMessage(Handler.java:102) でandroid.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460) で (ルーパー。 java:154) android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(ネイティブメソッド) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:865) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 原因:java.lang.RuntimeException:あなたのコンテンツには、id属性が 'android'のListViewが必要です。 R.id.list 'android.app.ListActivity.onContentChanged(ListActivity.java:243)の でcom.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:419) android.app.Activity.setContentView(Activity.java:2414) でcom.example.amila.newglossary.pst.onCreate( pst.java:42) android.app.Activity.performCreate(Activity.java:6664) (and Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread。 Javaの:2599)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707で )android.app.ActivityThread.-wrap12 android.app.ActivityThread $ H.handleMessageで(ActivityThread.java) で (ActivityThread.java :1460) android.os.Handler.d ispatchMessage(ハンドラ。java:102) android.os.Looper.loop(Looper.java:154) (android.app.ActivityThread.main(ActivityThread.java:6077)) at java.lang.reflect.Method.invoke(ネイティブメソッドで)com.android.internal.os.ZygoteInit.mainでcom.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865) (ZygoteInit.java:755)で
それは私のために働いた。 (他の言語)のフォントを2列目に変換するのですか?私は用語集app.soを試しています.1つの列は別の言語にする必要があります。 – amilab