Я сейчас нахожусь в процессе создания базового вида сетки с пользовательским макетом.хотя я пока показываю только текст в сетке.Я следую некоторому учебнику онлайн и следую всем шаг за шагом, я не получаю никакой ошибки от андроид студии и запускаю ее.Но когда я запускаю его, он показывает только пустую белую страницу.на этот раз я инициализировал адаптер, но он все равно ничего не показывает.помогите что я упустил в этом.
activity_main.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"
android:orientation="horizontal"
tools:context=".MainActivity">
<TextView
android:id="@+id/firsttext"
android:layout_width="match_parent"
android:layout_height="@dimen/ButtonSize"
android:text="@string/hello"
android:gravity="center"/>
<GridView
android:layout_below="@+id/firsttext"
android:id="@+id/firstList"
android:layout_width="match_parent"
android:layout_height="200dp"
android:columnWidth="100dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth">
</GridView>
</RelativeLayout>
gridlist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/gridtext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello"
android:textSize="@dimen/ButtonSize" />
</RelativeLayout>
gridadapter.java
public class gridAdapter extends BaseAdapter {
Context context;
String[] names;
LayoutInflater layoutInflater;
public gridAdapter(Context context,String[] names) {
this.context = context;
this.names = names;
}
@Override
public int getCount() {
return names.length;
}
@Override
public Object getItem(int position) {
return names[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View gridView = convertView;
if (convertView != null){
layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridView = layoutInflater.inflate(R.layout.gridlist,null);
}
TextView textView = (TextView)gridView.findViewById(R.id.gridtext);
textView.setText(names[position]);
return gridView;
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
String[] Names = {"great","good","average","great","good","average","great","good","average","great","good","average","great","good","average","great","good","average"};
GridView grid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
grid = (GridView)findViewById(R.id.firstList);
gridAdapter adapter = new gridAdapter(this,Names);
grid.setAdapter(adapter);
}
}