应用程序概述。
带标签的应用程序(3个标签:均为片段) 1)创建条目 2)检查记录 3)注意
1个标签:创建声音
包含一个具有3个选项的微调器,可以创建3种不同类型的声音。
纺纱包含
a)插入书籍(图书馆发行的书籍)
b)给朋友(如果这本书是给朋友的)
c)带给朋友(如果这本书被带给朋友)
在Spinner中选择一个选项会使同一活动中的条目布局变高。
a)-fragment_l_book_entry
b)-fragment_f_given_entry
c)-fragment_f_taken_entry
我在下面附上了本书条目布局的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="@drawable/border"
android:layout_marginTop="10dp"
>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Enter Book Name"
android:id="@+id/et1"
android:textAlignment="center"
android:textColor="#f16c1a"
android:layout_centerHorizontal="true"
/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/et2"
android:hint="Enter Book No."
android:textAlignment="center"
android:layout_gravity="center"
android:layout_below="@+id/et1"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/et3"
android:textSize="18dp"
android:inputType="date"
android:hint="Select Issue Date"
android:textAlignment="center"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_below="@+id/et2"
android:layout_centerHorizontal="true"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remind me to Return"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:id="@+id/cb1"
android:layout_below="@+id/et3"
android:layout_centerHorizontal="true"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/AlarmFL"
android:layout_below="@+id/cb1"
>
</FrameLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:textColor="#f08401"
android:id="@+id/saveentry"
android:layout_below="@id/AlarmFL"
android:layout_centerHorizontal="true"
/>
在第二个选项卡中,我具有相同的微调器和一个主要的“列表视图”,用于在其中设置自定义列表视图,以显示微调器选择的不同类型的项目。
输入图书
package com.example.monu.libraryassistant;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.Spinner;
import com.example.monu.libraryassistant.VarRecordFrags.FGivenEntry;
import com.example.monu.libraryassistant.VarRecordFrags.FTakenEntry;
import com.example.monu.libraryassistant.VarRecordFrags.LBookEntry;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class MakeEntry extends Fragment {
private Spinner spinner1;
private String entrytype[] = {"Book Entry","Given To Friend","Taken From Friend"};
private ArrayAdapter<String> entrytypeadapter;
private FrameLayout frameLayout;
private Fragment otherfragments[] = {new LBookEntry(), new FGivenEntry(), new FTakenEntry()};
private FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
private AdView mAdView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_make_entry, container, false);
MobileAds.initialize(getActivity(), "ca-app-pub-5567839560607947~5596808122");
mAdView = view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
spinner1 = (Spinner)view.findViewById(R.id.entrytypespinner);
entrytypeadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, entrytype);
spinner1.setAdapter(entrytypeadapter);
frameLayout = (FrameLayout)view.findViewById(R.id.FM1);
fragmentManager = getActivity().getSupportFragmentManager();
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.FM1,otherfragments[0]);
fragmentTransaction.commit();
break;
case 1:
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.FM1,otherfragments[1]);
fragmentTransaction.commit();
break;
case 2:
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.FM1,otherfragments[2]);
fragmentTransaction.commit();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
return view;
}
}
在主列表视图中设置自定义列表视图的“检查记录微调器活动”
package com.example.monu.libraryassistant;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import java.util.ArrayList;
public class CheckRecords extends Fragment {
/////////////FOR LIST VIEW/////////////////////
private ListView listView;
//////////////////////////////////////////////
///////////////////////////////////FOR Library Issued DATABASE LIST VIEW/////////////////////////////
public static ArrayList<String> LBookTitleList = new ArrayList<String>();
public static ArrayList<String> LBookNoList = new ArrayList<String>();
public static ArrayList<String> LIssuedateList = new ArrayList<String>();
public static ArrayList<String> LReminderList = new ArrayList<String>();
public static ArrayList<String> LReminderStatusList = new ArrayList<String>();
public static ArrayList<String> LEntryNo = new ArrayList<String>();
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////FOR Given DATABASE LIST VIEW/////////////////////////////
public static ArrayList<String> GBookTitleList = new ArrayList<String>();
public static ArrayList<String> GBookNoList = new ArrayList<String>();
public static ArrayList<String> GReminderList = new ArrayList<String>();
public static ArrayList<String> GFriendNameList = new ArrayList<String>();
public static ArrayList<String> GGivendateList = new ArrayList<String>();
public static ArrayList<String> GReminderStatusList = new ArrayList<String>();
public static ArrayList<String> GEntryNo = new ArrayList<String>();
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////FOR Taken Issued DATABASE LIST VIEW/////////////////////////////
public static ArrayList<String> TBookTitleList = new ArrayList<String>();
public static ArrayList<String> TBookNoList = new ArrayList<String>();
public static ArrayList<String> TReminderList = new ArrayList<String>();
public static ArrayList<String> TFriendNameList = new ArrayList<String>();
public static ArrayList<String> TTakendateList = new ArrayList<String>();
public static ArrayList<String> TEntryNo = new ArrayList<String>();
public static ArrayList<String> TReminderStatusList = new ArrayList<String>();
////////////////////////////////////////////////////////////////////////////////////////////////////
private Database database;
private SQLiteDatabase db;
private String selectrecordtype[] = {"Select Here","Book Entry","Given To Friend","Taken From Friend"};
private ArrayAdapter<String> selectrecordtypeadapter;
private Spinner recordtypespinner;
private AdView mAdView;
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_check_records, container, false);
listView = (ListView)view.findViewById(R.id.listview1);
MobileAds.initialize(getActivity(), "ca-app-pub-5567839560607947~5596808122");
mAdView = view.findViewById(R.id.adView2);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
recordtypespinner = (Spinner)view.findViewById(R.id.recordtypespinner);
selectrecordtypeadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, selectrecordtype);
recordtypespinner.setAdapter(selectrecordtypeadapter);
database = new Database(getActivity(), "bookrecords", null, 1);
db = database.getWritableDatabase();
recordtypespinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
switch (i){
case 0:
break;
case 1:
getItemsFromDatabase();
MyBaseAdapter myBaseAdapter = new MyBaseAdapter();
listView.setAdapter(myBaseAdapter);
break;
case 2:
getItemsFromDatabase_Given();
GivenToFriend givenToFriend = new GivenToFriend();
listView.setAdapter(givenToFriend);
break;
case 3:
getItemsFromDatabase_Taken();
TakenFromFriend takenFromFriend = new TakenFromFriend();
listView.setAdapter(takenFromFriend);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
return view;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////Library ISSUED/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void getItemsFromDatabase() {
LEntryNo.clear();
LBookTitleList.clear();
LBookNoList.clear();
LIssuedateList.clear();
LReminderList.clear();
LReminderStatusList.clear();
try{
Cursor cursor = db.rawQuery("select * from librarybookrecords", null);
while (cursor.moveToNext()) {
Log.e("get", cursor.getString(1)+":"+cursor.getString(2)+":"+cursor.getString(3)+":"+cursor.getString(4));
//Here i added data directly to lists in Custom Cart Class
LEntryNo.add(cursor.getString(0));
LBookTitleList.add(cursor.getString(1));
LBookNoList.add(cursor.getString(2));
LIssuedateList.add(cursor.getString(3));
LReminderStatusList.add(cursor.getString(4));
LReminderList.add(cursor.getString(5));
}
cursor.close();
}catch (SQLException e){
Log.e("DB Error", e.toString());
e.printStackTrace();
}
}
public class MyBaseAdapter extends BaseAdapter {
@Override
public int getCount() {
return LBookTitleList.size();
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
if(view==null) {
LayoutInflater layoutInflater = getLayoutInflater();
view = layoutInflater.inflate(R.layout.customlistreocrds, null);
}
TextView textView1 = (TextView)view.findViewById(R.id.booknametitle);
TextView textView2 = (TextView)view.findViewById(R.id.booknotitle);
TextView textView3 = (TextView)view.findViewById(R.id.bookissuedatetitle);
TextView textView4 = (TextView)view.findViewById(R.id.bookreminderdateandtime);
ImageView imageView = (ImageView)view.findViewById(R.id.deleterecordbutton);
ImageView imageView1 = view.findViewById(R.id.reminderindicator);
textView1.setText("Book Name : "+LBookTitleList.get(i));
textView2.setText("Book No : "+LBookNoList.get(i));
textView3.setText("Issue Date : "+LIssuedateList.get(i));
textView4.setText("Reminder Date : "+LReminderList.get(i));
imageView.setImageResource(R.drawable.delete);
if (LReminderStatusList.get(i).equals("true")){
imageView1.setImageResource(R.drawable.alarm_on);
}
else {
imageView1.setImageResource(R.drawable.alarm_off);
}
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String str = LEntryNo.get(i);
Integer inte = Integer.parseInt(str);
String deletequery = "delete from librarybookrecords where bkno = '"+str+"'";
db.execSQL(deletequery);
Log.e("deleted",deletequery+str);
getItemsFromDatabase();
notifyDataSetChanged();
}
});
MyBaseAdapter myBaseAdapter = new MyBaseAdapter();
myBaseAdapter.notifyDataSetChanged();
return view;
}
}
我该怎么做:
当我在*输入条目*选项卡上选择*图书条目*并同时在*检查记录*选项卡上选择了我时,我在*主列表视图*中设置了图书记录,该记录显示了我在同一类别。
但是,当我在“创建条目”选项卡上添加记录并滚动到“检查记录”选项卡时,该记录已经显示了相同的类别记录,它不会更新我创建的最后一个条目。