Test Class:
package com.aokdev.aokgame_1;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class test extends AppCompatActivity {
EditText editText;
Button buttonAdd;
ListView listView;
List<Integer> adet = new ArrayList<Integer>();
List<Integer> hafiza = new ArrayList<Integer>();
ArrayList<veri> array = new ArrayList<veri>();
myAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
editText = (EditText)findViewById(R.id.editTextNumber);
buttonAdd = (Button)findViewById(R.id.buttonAdd);
listView = (ListView)findViewById(R.id.list);
adapter = new myAdapter(getApplicationContext(),
R.layout.icerik);
listView.setAdapter(adapter);
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int neresinde =0;
if(!"".equals(String.valueOf(editText.getText())))
{
int gelen = Integer.parseInt(String.valueOf(editText.getText()));
boolean varMi = false;
for(int i=0;i<hafiza.size();i++)
{
if(hafiza.get(i) == gelen)
{
varMi = true;
neresinde = i;
}
}
if(varMi)
{
int aktar = adet.get(neresinde);
adet.set(neresinde, aktar+1);
String ss = String.valueOf(hafiza.get(neresinde)) + " sayısından "+ String.valueOf(adet.get(neresinde)) + " adet girildi";
adapter.update(neresinde, ss);
}
else
{
hafiza.add(gelen);
adet.add(1);
String ss = String.valueOf(hafiza.get(hafiza.size()-1)) + " sayısından "+ String.valueOf(adet.get(adet.size()-1)) + " adet girildi";
adapter.add(new veri(ss));
}
}
else
{
//Toast.makeText(getApplicationContext(), "Veri Girmediniz", Toast.LENGTH_SHORT).show();
}
listView.setAdapter(adapter);
}
});
}
public class veri
{
public String data;
public veri(String data)
{
this.data = data;
}
public void setData(String data) {
this.data = data;
}
public String getData() {
return data;
}
}
public class myAdapter extends ArrayAdapter<veri>
{
Context context;
List<veri> l = new ArrayList<veri>();
public myAdapter(Context context, int resource) {
super(context, resource);
this.context = context;
}
public void update(int possiton, String object)
{
l.get(possiton).data = object;
}
@Override
public veri getItem(int position) {
return l.get(position);
}
@Override
public void add(veri object) {
super.add(object);
l.add(object);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView= inflater.inflate(R.layout.icerik, null, true);
veri v = l.get(position);
TextView textView = (TextView)rowView.findViewById(R.id.textView);
textView.setText(String.valueOf(v.data));
//Toast.makeText(context, v.data , Toast.LENGTH_SHORT).show();
return rowView;
}
}
}
activity_test.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.aokdev.aokgame_1.test">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editTextNumber" />
<Button
android:text="Add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonAdd" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list" />
</LinearLayout>
</RelativeLayout>
icerik.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textColor="@android:color/black"
android:textSize="16sp" />
</LinearLayout>
İçinden sana lazım olan java kısmını alabilirsin =) işini gördüyse doğru cevap olarak işaretlemeyi unutma. İyi çalışmalar.