我正在尝试显示java课程列表,并在Android Studio的主java类中为按钮创建了一个列表视图,但是当我尝试运行并单击该按钮时,它会打开另一个窗口,但列表视图不会出现这样的情况。 t显示它位于Android Studio的预览窗格上。
这是我的java类代码:
package unitysoftwenteam.mymainuidesign;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.List;
public class JAVA_ACTIVITY extends AppCompatActivity {
ListView listview;
List list = new ArrayList();
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_java__activity);
listview = (ListView)findViewById(R.id.jtutoriallist);
list.add("About Java");
list.add("Print Hello Java");
list.add("Variables");
list.add("Updating Variables");
list.add("Displaying the Output");
list.add("String Variables");
list.add("String Concatenation");
list.add("Variable Names");
list.add("Data Types");
list.add("Variable Arithmetic");
list.add("Casting");
list.add("Control Flow");
list.add("If Statement");
list.add("Variable Scope");
list.add("Else Statement");
list.add("Else-If");
list.add("Boolean Expressions");
list.add("Logical Operators");
list.add("Nested If Statements");
list.add("Switch Statement");
adapter = new ArrayAdapter(JAVA_ACTIVITY.this,
android.R.layout.simple_list_item_1);
listview.setAdapter(adapter);
}
}
这是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="unitysoftwenteam.mymainuidesign.JAVA_ACTIVITY">
<ListView
android:id="@+id/jtutoriallist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
答案 0 :(得分:1)
实际上你做的每件事情都是正确的,但你只需要指定要用ini_set("log_errors", 0);
调整的列表:
<VirtualHost *:80>
ServerAdmin admin@myapp.dev
ServerName myapp.dev
ServerAlias www.myapp.dev
DocumentRoot /home/vagrant/code/public
ErrorLog /dev/null
CustomLog /dev/null common
</VirtualHost>
答案 1 :(得分:0)
试用此代码
ListView listview;
List list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = new ArrayList();
listview= (ListView) findViewById(R.id.jtutoriallist);
lists = (ListView) findViewById(R.id.lists);
list.add("About Java");
list.add("Print Hello Java");
list.add("Variables");
list.add("Updating Variables");
.
.
.
ArrayAdapter adapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, list);
lists.setAdapter(adapter);
}
答案 2 :(得分:0)
您错过了将数据发送到适配器。 &#39;列表&#39;你创造了。适配器需要数据和视图来绑定和填充相同的内容。你已经指定了布局但是错过了数据。
只需将其更改为,
adapter = new ArrayAdapter(JAVA_ACTIVITY.this,
android.R.layout.simple_list_item_1,list);
listview.setAdapter(adapter);