Android 我使用了3个选项卡第一个和最后一个选项卡是刷新数据,然后当我单击中心选项卡时,无法刷新我所做的操作。?
我使用了3个选项卡(请求、到达、左)单击该选项卡时,第一个选项卡和最后一个选项卡将刷新,但中心选项卡无法刷新如何帮助我 我的代码: VisitorListItems.javaAndroid 我使用了3个选项卡第一个和最后一个选项卡是刷新数据,然后当我单击中心选项卡时,无法刷新我所做的操作。?,android,android-fragments,arraylist,tabs,android-arrayadapter,Android,Android Fragments,Arraylist,Tabs,Android Arrayadapter,我使用了3个选项卡(请求、到达、左)单击该选项卡时,第一个选项卡和最后一个选项卡将刷新,但中心选项卡无法刷新如何帮助我 我的代码: VisitorListItems.java public class VisitorListItems { String visitorname,mobileno,whomtomeet,date,time; int Reg_id; Bitmap visitorimg; public VisitorListItems(String vi
public class VisitorListItems {
String visitorname,mobileno,whomtomeet,date,time;
int Reg_id;
Bitmap visitorimg;
public VisitorListItems(String visitorname,String mobileno,String whomtomeet,Bitmap visitorimg,String date,String time,int Reg_id){
this.visitorname=visitorname;
this.mobileno=mobileno;
this.whomtomeet=whomtomeet;
this.visitorimg=visitorimg;
this.date=date;
this.time=time;
this.Reg_id=Reg_id;
}
public String getVisitorname(){
return visitorname;
}
public String getMobileno(){return mobileno; }
public String getWhomtomeet(){
return whomtomeet;
}
public String getDate() { return date; }
public String getTime(){return time;}
public Bitmap getVisitorimg(){
return visitorimg;
}
public int getReg_id(){return Reg_id;}
}
MyListviewAdapter.java
public class MyListviewAdapter extends ArrayAdapter<VisitorListItems> {
String RegIdno;
private Button btnallow;
private Button btndeny;
private ProgressDialog pbd;
private TextView txtWhomtomeet,txtdate,txttimein,txtregidno,txtmobil;
ArrayList<VisitorListItems> visitorlist=new ArrayList<>();
ConnectionClass connectionClass;
public MyListviewAdapter(Context context,int textViewResourceId, ArrayList<VisitorListItems> objects) {
super(context,textViewResourceId,objects);
visitorlist=objects;
}
@Override
public int getCount() {
return super.getCount();
}
@Override
public View getView(int position, View convertview, ViewGroup parent){
View v=convertview;
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.registrationlisttemplate, null);
connectionClass=new ConnectionClass();
TextView txtvisitorname = (TextView) v.findViewById(R.id.txtvisitorname);
btnallow=(Button)v.findViewById(R.id.btnallow);
btndeny=(Button)v.findViewById(R.id.btndeny);
txtWhomtomeet = (TextView) v.findViewById(R.id.txtWhomtomeet);
txtdate=(TextView)v.findViewById(R.id.txtdate);
txttimein=(TextView)v.findViewById(R.id.txttimein);
txtregidno=(TextView)v.findViewById(R.id.txtregidno);
txtmobil = (TextView) v.findViewById(R.id.txtmobil);
ImageView imageView = (ImageView) v.findViewById(R.id.imgvisitor);
txtvisitorname.setText(visitorlist.get(position).getVisitorname());
txtWhomtomeet.setText(visitorlist.get(position).getWhomtomeet());
txtmobil.setText(visitorlist.get(position).getMobileno());
imageView.setImageBitmap(visitorlist.get(position).getVisitorimg());
txtdate.setText(visitorlist.get(position).getDate());
txttimein.setText(visitorlist.get(position).getTime());
txtregidno.setText(String.valueOf(visitorlist.get(position).getReg_id()));
txtregidno.setVisibility(View.INVISIBLE);
btnallow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RegIdno=txtregidno.getText().toString();
Visitorallow visitorallow=new Visitorallow();
visitorallow.execute("");
}
});
btndeny.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RegIdno=txtregidno.getText().toString();
Visitordeny visitordeny=new Visitordeny();
visitordeny.execute("");
// Toast.makeText(getContext(),M,Toast.LENGTH_SHORT).show();
}
});
return v;
}
public class Visitorallow extends AsyncTask<String,String,String> {
String Z="";
Boolean isSuccess;
@Override
protected String doInBackground(String... params) {
try{
Connection con=connectionClass.CONN();
if(con==null){
Z="Error in Connection with SQL Server";
}
else {
String query="Update app_Registration set FlatOwner='"+1+"' where Id='"+RegIdno+"'";
PreparedStatement preparedStatement=con.prepareStatement(query);
preparedStatement.executeUpdate();
Z="Update Successfully";
isSuccess=true;
}
}catch (Exception ex){
isSuccess=false;
Z="Exception";
}
return Z;
}
@Override
protected void onPreExecute() {
// super.onPreExecute();
pbd=new ProgressDialog(getContext());
pbd.setMessage("Please Wait...");
pbd.setCancelable(false);
pbd.show();
}
@Override
protected void onPostExecute(String s) {
// super.onPostExecute(s);
if(pbd.isShowing())
pbd.dismiss();
// btndeny.setVisibility(View.GONE);
Toast.makeText(getContext(),s,Toast.LENGTH_SHORT).show();
}
}
public class Visitordeny extends AsyncTask<String,String,String> {
String Z="";
Boolean isSuccess;
@Override
protected String doInBackground(String... params) {
try{
Connection con=connectionClass.CONN();
if(con==null){
Z="Error in Connection with SQL Server";
}
else {
String query="Update app_Registration set FlatOwner='"+0+"' where Id='"+RegIdno+"'";
PreparedStatement preparedStatement=con.prepareStatement(query);
preparedStatement.executeUpdate();
Z="Update Successfully";
isSuccess=true;
}
}catch (Exception ex){
isSuccess=false;
Z="Exception";
}
return Z;
}
@Override
protected void onPreExecute() {
// super.onPreExecute();
pbd=new ProgressDialog(getContext());
pbd.setMessage("Please Wait...");
pbd.setCancelable(false);
pbd.show();
}
@Override
protected void onPostExecute(String s) {
// super.onPostExecute(s);
if(pbd.isShowing())
pbd.dismiss();
// btndeny.setVisibility(View.GONE);
Toast.makeText(getContext(),s,Toast.LENGTH_SHORT).show();
}
}
}
公共类MyListviewAdapter扩展了ArrayAdapter{
字符串RegIdno;
私人按钮btnallow;
私用按钮;
私人发展对话;
私有文本视图txtwhomet、txtdate、txttimein、txtregidno、txtmobil;
ArrayList visitorlist=新建ArrayList();
连接类连接类;
公共MyListviewAdapter(上下文上下文、int-textViewResourceId、ArrayList对象){
超级(上下文、textViewResourceId、对象);
visitorlist=对象;
}
@凌驾
public int getCount(){
返回super.getCount();
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
LayoutInflater充气器=(LayoutInflater)getContext().getSystemService(Context.LAYOUT\u充气器\u SERVICE);
v=充气机充气(R.layout.registrationlisttemplate,空);
connectionClass=新的connectionClass();
TextView txtvisitorname=(TextView)v.findViewById(R.id.txtvisitorname);
btnallow=(按钮)v.findviewbyd(R.id.btnallow);
btndeny=(按钮)v.findViewById(R.id.btndeny);
txtwohmtomeet=(TextView)v.findViewById(R.id.txtwohmtomeet);
txtdate=(TextView)v.findViewById(R.id.txtdate);
txttimein=(TextView)v.findViewById(R.id.txttimein);
txtregidno=(TextView)v.findViewById(R.id.txtregidno);
txtmobil=(TextView)v.findviewbyd(R.id.txtmobil);
ImageView ImageView=(ImageView)v.findViewById(R.id.imgvisitor);
txtvisitorname.setText(visitorlist.get(position.getVisitorname());
setText(visitorlist.get(position.getWhomtomeet());
setText(visitorlist.get(position.getMobileno());
setImageBitmap(visitorlist.get(position.getVisitorimg());
setText(visitorlist.get(position.getDate());
setText(visitorlist.get(position.getTime());
txtregidno.setText(String.valueOf(visitorlist.get(position.getReg_id());
txtregidno.setVisibility(视图不可见);
btnallow.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
RegIdno=txtregidno.getText().toString();
Visitorallow Visitorallow=新建Visitorallow();
visitorallow.execute(“”);
}
});
btdeny.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
RegIdno=txtregidno.getText().toString();
Visitordeny Visitordeny=新建Visitordeny();
visitordeny.execute(“”);
//Toast.makeText(getContext(),M,Toast.LENGTH_SHORT).show();
}
});
返回v;
}
公共类Visitorallow扩展异步任务{
字符串Z=“”;
布尔不成功;
@凌驾
受保护的字符串doInBackground(字符串…参数){
试一试{
Connection con=connectionClass.CONN();
如果(con==null){
Z=“与SQL Server连接时出错”;
}
否则{
String query=“Update app_Registration set FlatOwner=”“+1+”,其中Id=”“+RegIdno+”;
PreparedStatement PreparedStatement=con.prepareStatement(查询);
preparedStatement.executeUpdate();
Z=“更新成功”;
isSuccess=true;
}
}捕获(例外情况除外){
isSuccess=false;
Z=“例外”;
}
返回Z;
}
@凌驾
受保护的void onPreExecute(){
//super.onPreExecute();
pbd=新建ProgressDialog(getContext());
设置消息(“请稍候…”);
pbd.setCancelable(假);
pbd.show();
}
@凌驾
受保护的void onPostExecute(字符串s){
//super.onPostExecute(s);
if(pbd.isShowing())
pbd.discouse();
//btdeny.setVisibility(View.GONE);
Toast.makeText(getContext(),s,Toast.LENGTH_SHORT).show();
}
}
公共类Visitordeny扩展异步任务{
字符串Z=“”;
布尔不成功;
@凌驾
受保护的字符串doInBackground(字符串…参数){
试一试{
Connection con=connectionClass.CONN();
如果(con==null){
Z=“与SQL Server连接时出错”;
}
否则{
String query=“Update app_Registration set FlatOwner=”“+0+”,其中Id=”“+RegIdno+”;
PreparedStatement PreparedStatement=con.prepareStatement(查询);
preparedStatement.executeUpdate();
Z=“更新成功”;
isSuccess=true;
}
}捕获(例外情况除外){
isSuccess=false;
Z=“例外”;
}
返回Z;
}
@凌驾
受保护的void onPreExecute(){
//super.onPreExecute();
pbd=新建ProgressDialog(getContext());
设置消息(“请稍候…”);
pbd.setCancelable(假);
pbd.show();
}
@凌驾
受保护的void onPostExecute(字符串s){
//super.onPostExecute(s);
if(pbd.isShowing())
pbd.discouse();
//btdeny.setVisibility(View.GONE);
Toast.makeText(getContext(
public class VisitorList extends Fragment {
// private ProgressDialog pbbar;
//private ProgressBar pbbar;
private ProgressDialog pbd;
private ListView lstview;
ConnectionClass connectionClass;
String Y = "";
String mobileno;
int RegIdNo;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mobileno=getActivity().getIntent().getStringExtra("user_name");
View rootView = inflater.inflate(R.layout.visitorlistslide, container, false);
lstview = (ListView) rootView.findViewById(R.id.lstview);
// txtregid=(TextView)rootView.findViewById(R.id.txtregid);
connectionClass = new ConnectionClass();
Fetch fetch = new Fetch();
fetch.execute("");
return rootView;
}
public class Fetch extends AsyncTask<String, String, String> {
String z = "";
ArrayList<VisitorListItems> visitorList=new ArrayList<>();
@Override
protected void onPreExecute() {
pbd=new ProgressDialog(getActivity());
pbd.setMessage("Please Wait...");
pbd.setCancelable(false);
pbd.show();
}
@Override
protected void onPostExecute(String r) {
// pbbar.setVisibility(View.GONE);
if (pbd.isShowing())
pbd.dismiss();
// txtregid.setText(String.valueOf(Reg_Id));
Toast.makeText(getActivity(), r, Toast.LENGTH_SHORT).show();
MyListviewAdapter myAdapter=new MyListviewAdapter(getActivity(),R.layout.registrationlisttemplate,visitorList);
// myAdapter.notifyDataSetChanged();
lstview.setAdapter(myAdapter);
}
@Override
protected String doInBackground(String... params) {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with SQL server";
} else {
String query = "select * from app_Registration where OwnerMobileNo='"+ mobileno+"' and FlatOwner is null and Security=1";
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
ArrayList data1 = new ArrayList();
while (rs.next()) {
//Reg_Id=rs.getInt("Id");
RegIdNo=rs.getInt("Id");
String r=rs.getString("VisitorImg");
//Convertong Images string to bitmap
byte[] decodeString = Base64.decode(r, Base64.DEFAULT);
Bitmap decodebitmap = BitmapFactory.decodeByteArray(decodeString,0, decodeString.length);
visitorList.add(new VisitorListItems("VisitorName : " + rs.getString("VisitorName"),"Whomtomeet : " + rs.getString("Whomtomeet"),"Mobile No. : " + rs.getString("MobileNo"),decodebitmap,"Visit Date :"+rs.getString("datein"),rs.getString("timein"),RegIdNo));
}
z = "Success";
}
} catch (Exception ex) {
z = "Error retrieving data from table";
}
return z;
}
}
}
public class VisitorList extends Fragment {
// private ProgressDialog pbbar;
//private ProgressBar pbbar;
private ProgressDialog pbd;
private ListView lstview;
ConnectionClass connectionClass;
String Y = "";
String mobileno;
int RegIdNo;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mobileno=getActivity().getIntent().getStringExtra("user_name");
View rootView = inflater.inflate(R.layout.visitorlistslide, container, false);
lstview = (ListView) rootView.findViewById(R.id.lstview);
// txtregid=(TextView)rootView.findViewById(R.id.txtregid);
return rootView;
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
// write here the code of refresh the data
connectionClass = new ConnectionClass();
Fetch fetch = new Fetch();
fetch.execute("");
}
}
public class Fetch extends AsyncTask<String, String, String> {
String z = "";
ArrayList<VisitorListItems> visitorList=new ArrayList<>();
@Override
protected void onPreExecute() {
pbd=new ProgressDialog(getActivity());
pbd.setMessage("Please Wait...");
pbd.setCancelable(false);
pbd.show();
}
@Override
protected void onPostExecute(String r) {
// pbbar.setVisibility(View.GONE);
if (pbd.isShowing())
pbd.dismiss();
// txtregid.setText(String.valueOf(Reg_Id));
Toast.makeText(getActivity(), r, Toast.LENGTH_SHORT).show();
MyListviewAdapter myAdapter=new MyListviewAdapter(getActivity(),R.layout.registrationlisttemplate,visitorList);
// myAdapter.notifyDataSetChanged();
lstview.setAdapter(myAdapter);
}
@Override
protected String doInBackground(String... params) {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with SQL server";
} else {
String query = "select * from app_Registration where OwnerMobileNo='"+ mobileno+"' and FlatOwner is null and Security=1";
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
ArrayList data1 = new ArrayList();
while (rs.next()) {
//Reg_Id=rs.getInt("Id");
RegIdNo=rs.getInt("Id");
String r=rs.getString("VisitorImg");
//Convertong Images string to bitmap
byte[] decodeString = Base64.decode(r, Base64.DEFAULT);
Bitmap decodebitmap = BitmapFactory.decodeByteArray(decodeString,0, decodeString.length);
visitorList.add(new VisitorListItems("VisitorName : " + rs.getString("VisitorName"),"Whomtomeet : " + rs.getString("Whomtomeet"),"Mobile No. : " + rs.getString("MobileNo"),decodebitmap,"Visit Date :"+rs.getString("datein"),rs.getString("timein"),RegIdNo));
}
z = "Success";
}
} catch (Exception ex) {
z = "Error retrieving data from table";
}
return z;
}
}
}