• 第八周总结


    本周学习了android的fragment

    package net.hnjdzy.tinyaccount.fragment;


    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    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.Button;
    import android.widget.ListView;
    import android.widget.TextView;
    import net.hnjdzy.tinyaccount.R;
    import net.hnjdzy.tinyaccount.activity.AccountEditActivity;
    import net.hnjdzy.tinyaccount.adapter.AccountItemAdapter;
    import net.hnjdzy.tinyaccount.db.AccountDao;
    import net.hnjdzy.tinyaccount.entity.AccountItem;
    import android.widget.AdapterView.OnItemLongClickListener;
    import java.util.ArrayList;
    import java.util.List;


    /**
    * 收入列表
    * @author androiddev@163.com,hnjdzy
    */
    public class IncomeFragment extends Fragment {
    View mRootView;

    public IncomeFragment() {
    // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    mRootView = inflater.inflate(R.layout.fragment_income, container, false);
    initView();
    return mRootView;
    }

    // 初始化
    private void initView() {

    Button buttonAdd = (Button)mRootView.findViewById(R.id.buttonAdd);
    buttonAdd.setOnClickListener(new View.OnClickListener(){

    @Override
    public void onClick(View v) {
    buttonAddOnClick();
    }

    });
    ListView listView = (ListView)mRootView.findViewById(R.id.listView1);
    listView.setOnItemLongClickListener(new OnItemLongClickListener(){

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view,
    int position, long id) {
    deleteItem(id);
    return true;
    }

    });
    refreshData();
    }
    protected void buttonAddOnClick() {
    Intent intent =new Intent(this.getActivity(), AccountEditActivity.class);
    intent.putExtra("isIncome", true);
    this.startActivityForResult(intent, 1);
    //startActivity(intent);
    }

    //刷新界面
    private void refreshData() {
    AccountDao dbManager = new AccountDao(getContext());
    // List<AccountItem> incomeAccountList = getTestData();
    List<AccountItem> incomeAccountList = dbManager.getIncomeList();

    AccountItemAdapter adapter = new AccountItemAdapter(incomeAccountList,getActivity());
    ListView listView = (ListView) mRootView.findViewById(R.id.listView1);
    listView.setAdapter(adapter);

    TextView textViewIncomeSummary = (TextView) mRootView.findViewById(R.id.textViewIncomeSummary);
    textViewIncomeSummary.setText("10000");
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("tinyaccount","onActivityResult");
    refreshData();
    }

    protected void deleteItem(final long id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
    builder.setTitle(R.string.delete_confirm_title);
    builder.setMessage(R.string.delete_confirm_msg);

    builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    AccountDao dbManager = new AccountDao(getContext());
    dbManager.deleteIncome(id);
    refreshData();
    }
    });
    builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    dialog.cancel();
    }
    });

    builder.show();


    }

    private List<AccountItem> getTestData() {
    List<AccountItem> result = new ArrayList<>();
    for(int i=0;i<5;i++) {
    AccountItem item = new AccountItem();
    item.setId(i);
    item.setCategory("兼职收入");
    item.setMoney(100*i);
    item.setDate("2019-01-0"+i);
    result.add(item);
    }
    return result;
    }

    }
  • 相关阅读:
    如何查看操作系统的具体版本号
    Review of Image Super-resolution Reconstruction Based on Deep Learning
    opencv imshow图片显示不全
    Javaweb文件下载异常
    Microsoft Edge出现错误代码:STATUS_INVALID_IMAGE_HASH
    Javaweb导入excel数据
    Java读取execl数据
    浏览器网页左上角小图标实现方式
    Java LDAP验证
    Java JPA新增数据生成UUID
  • 原文地址:https://www.cnblogs.com/w669399221/p/13087018.html
Copyright © 2020-2023  润新知