При нажатии на элемент списка ничего не происходит. Код: MainActivity.java
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MAIN ACTIVITY";
private Button buttonStart;
private ListView listView;
private MainListAdapter listAdapter;
private ArrayList<Paket> mList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonStart = (Button)findViewById(R.id.btnStart);
listView = (ListView)findViewById(R.id.listView);
mList = new ArrayList<>();
fillArray();
listAdapter = new MainListAdapter(this, mList);
listView.setAdapter(listAdapter);
initListener();
}
private void initListener() {
buttonStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Button pressed");
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick()");
startActivity(new Intent(getApplicationContext(), LearnActivity.class));
}
});
}
private void fillArray() {
for (int i = 0; i<10; i++){
mList.add(new Paket());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
MainListAdapter.java
public class MainListAdapter extends BaseAdapter{
private static final String TAG = "LIST_ADAPTER_TAG";
Context context;
LayoutInflater lInflater;
ArrayList<Paket> mList;
Filter filter = null;
public MainListAdapter(Context context, ArrayList<Paket> list) {
this.context = context;
this.mList = list;
lInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int position) {
return mList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.item_list_main, parent, false);
}
Paket paket = mList.get(position);
((TextView) view.findViewById(R.id.title)).setText(paket.getmTitle());
((TextView)view.findViewById(R.id.description)).setText(paket.getmDescription());
((TextView)view.findViewById(R.id.count)).setText(paket.getmWordCount());
((Button)view.findViewById(R.id.btnBuy)).setText(paket.getmPrice());
return view;
}
private String getString(int position) {
return ((String) getItem(position));
}
}
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:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/linearLayout"
android:layout_below="@+id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="НАЧАТЬ"
android:id="@+id/btnStart"
android:layout_width="329dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:textColor="@color/colorWhite"
android:background="@color/colorGreen"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout"
>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:divider="@android:color/transparent"
android:dividerHeight="3.0sp"/>
</RelativeLayout>