TextView Sorunu
03.08.2017 - 02:18
İkinci sıraya neden textView ekleyemiyorum?
Main Activity'im
GridView gridView;
String[] dizi = {
"7", "8", "9", "C", "4", "5", "6", "/", "1", "2", "3", "*", "0", "=", "+", "-"
};
@Override
protected void onCreate(javascript:void(0)Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.gridView1);
ArrayAdapter<String> adapter = new MyAdapter(this);
adapter.addAll(dizi);//diziyi adaptöre gönderdik.
gridView.setAdapter(adapter);//gridview ve adaptörü bağladık.
adapter.notifyDataSetChanged();
}
private class MyAdapter extends ArrayAdapter<String> {//adaptörü sınıf olarak oluşturduk.
MyAdapter(@NonNull Context context) {
super(context, android.R.layout.simple_list_item_1);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {// pozisyonunu alır ve çizer
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.calc_button, parent, false);//VİEWVİ GÖRSEL HALE GETİRRİ INFLATER
}
TextView button = (TextView) convertView;
button.setText(getItem(position));//pozisyonu alır.
return button;
}
}
}
Click and drag to move
calc_button.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="@+id/textView2"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="7"
android:textAlignment="center"
android:layout_weight="0.05"></TextView>
<TextView
android:id="@+id/textView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="8"
android:textAlignment="center"></TextView>
<TextView
android:id="@+id/textView3"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="9"
android:textAlignment="center"></TextView>
<TextView
android:id="@+id/textView"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="C"
android:textAlignment="center"></TextView>
</LinearLayout>
304
Görüntülenme
0 Beğeni