今天学习python的基础语法数据类型的学习,学习了数组的计算和地址查找。
课后回到宿舍学习了 java编写app的逻辑代码。
package com.example.xx.frg_recod; import android.inputmethodservice.KeyboardView; import android.os.Bundle; import androidx.fragment.app.Fragment; import android.text.style.TypefaceSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.EditText; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView; import com.example.xx.R; import com.example.xx.db.DBManager; import com.example.xx.db.TypeBean; import com.example.xx.util.KeyBordUtil; import java.util.ArrayList; import java.util.List; /** * A simple {@link Fragment} subclass. * Use the {@link OutcomeFragment#newInstance} factory method to * create an instance of this fragment. */ public class OutcomeFragment extends Fragment { KeyboardView keyboardView; EditText editText; ImageView typeiv; TextView typeTv,beizhuTv,timeTv; GridView typegv; List<TypeBean> typeList; TypeBaseAdapter typeBaseAdapter; // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; public OutcomeFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment OutcomeFragment. */ // TODO: Rename and change types and number of parameters public static OutcomeFragment newInstance(String param1, String param2) { OutcomeFragment fragment = new OutcomeFragment(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view= inflater.inflate(R.layout.fragment_outcome, container, false); initView(view); loadDataToGv(); setGVListener(); return view; } private void setGVListener() { typegv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { typeBaseAdapter.selectpos=i; typeBaseAdapter.notifyDataSetChanged(); TypeBean typeBean=typeList.get(i); String typename=typeBean.getTypename(); typeTv.setText(typename); int simageid=typeBean.getSimageid(); typeiv.setImageResource(simageid); } }); } private void loadDataToGv() { typeList=new ArrayList<>(); TypeBaseAdapter typeBaseAdapter = new TypeBaseAdapter(getContext(), typeList); typegv.setAdapter(typeBaseAdapter); //获取数据库数据源 List<TypeBean> outlist=DBManager.getTypelist(0); typeList.addAll(outlist); typeBaseAdapter.notifyDataSetChanged(); } private void initView(View view) { keyboardView=view.findViewById(R.id.frag_record_keybord); editText=view.findViewById(R.id.frag_record_et_money); typeiv=view.findViewById(R.id.frag_record_iv); typegv=view.findViewById(R.id.frag_record_gv); typeTv=view.findViewById(R.id.frag_record_tv_type); beizhuTv=view.findViewById(R.id.frag_record_tv_beizhu); timeTv=view.findViewById((R.id.frag_record_tv_time)); KeyBordUtil bordUtil=new KeyBordUtil(keyboardView,editText); bordUtil.showKeyboard(); //设置接口,监听确定按钮被点击 bordUtil.setOnEnsureListener(new KeyBordUtil.onEnsureListener() { @Override public void onEnsure() { //点击了确定按钮 //获取记录的信息保存到数据库 //返回上一级 } }); } }
package com.example.xx.frg_recod; import android.content.Context; import android.icu.text.Transliterator; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.textclassifier.ConversationAction; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.ContentView; import com.example.xx.R; import com.example.xx.db.TypeBean; import java.util.List; public class TypeBaseAdapter extends BaseAdapter { Context context; List<TypeBean> mDatas; int selectpos= 0;//选中位置 public TypeBaseAdapter(Context context, List<TypeBean> mDatas) { this.context = context; this.mDatas = mDatas; } @Override public int getCount() { return mDatas.size(); } @Override public Object getItem(int i) { return mDatas.get(i); } @Override public long getItemId(int i) { return i; } @Override public View getView(int i, View view, ViewGroup viewGroup) { view= LayoutInflater.from(context).inflate(R.layout.item_recordfrag_gv,viewGroup,false); //查找布局控件 ImageView imageView=view.findViewById(R.id.item_recordfrag_iv); TextView textView=view.findViewById(R.id.item_recordfrag_tv); TypeBean typeBean= mDatas.get(i); textView.setText(typeBean.getTypename()); if (selectpos==i) { imageView.setImageResource(typeBean.getSimageid()); }else{ imageView.setImageResource(typeBean.getImageid()); } return view; } }
标签:总结,fragment,每日,2.28,new,import,android,public,view From: https://www.cnblogs.com/syhxx/p/17166173.html