从零开始的体温app开发(ThirdActivity)
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.List;
import adapter.UserListAdapter;
import adapter.UserListAdapter2;
import bean.User;
import bean.User2;
import dao.UserDao;
import dao.UserDao2;
public class ThirdActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AbsListView.OnScrollListener {
private ListView mUserList;
private UserDao2 userDao=null;
private List<User2> userList=null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
mUserList=findViewById(R.id.user_list2);
InitData();
mUserList.setOnItemClickListener(this);
mUserList.setOnScrollListener(this);
}
private void InitData(){
userDao=UserDao2.getInstance(getApplicationContext());
userList=userDao.findAll();
UserListAdapter2 adapter=new UserListAdapter2(getApplicationContext(),userList);
mUserList.setAdapter(adapter);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent();
Log.e("position",""+position);
Toast.makeText(getApplicationContext(), "切换成功", Toast.LENGTH_SHORT).show();
intent.putExtra("message",position);
intent.setClass(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
}