Android Open Source - ArchPad C Sight Select Fragment






From Project

Back to project page ArchPad.

License

The source code is released under:

GNU General Public License

If you think the Android project ArchPad listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.Andryyo.ArchPad.sight;
//  w  ww. jav  a2 s  . c  o m
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import com.Andryyo.ArchPad.R;
import com.Andryyo.ArchPad.database.CSQLiteOpenHelper;

/**
 * Created with IntelliJ IDEA.
 * User: ???????
 * Date: 13.06.13
 * Time: 21:09
 * To change this template use File | Settings | File Templates.
 */
public class CSightSelectFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener, DialogInterface.OnClickListener {

    SimpleCursorAdapter adapter;
    Spinner spinner;
    long selectedItemId;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)  {
        View view = inflater.inflate(R.layout.sight_select_fragment, null);
        view.findViewById(R.id.addSight).setOnClickListener(this);
        view.findViewById(R.id.deleteSight).setOnClickListener(this);
        adapter = new SimpleCursorAdapter(getActivity(),
                R.layout.spinner_child_2,
                null,
                new String[]{"name","description"},
                new int[]{R.id.text1,R.id.text2});
        spinner = (Spinner)view.findViewById(R.id.spinner);
        spinner.setAdapter(adapter);
        getLoaderManager().initLoader(0, null, this);
        return view;
    }

    public void update()    {
        getLoaderManager().restartLoader(0, null, this);
    }

    public void setSelection(long sightId) {
        selectedItemId = sightId;
    }

    @Override
    public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
        return CSQLiteOpenHelper.getCursorLoader(getActivity(), CSQLiteOpenHelper.TABLE_SIGHTS);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> objectLoader, Cursor cursor) {
        adapter.changeCursor(cursor);
        for (int i = 0;i<adapter.getCount();i++)
            if (adapter.getItemId(i)==selectedItemId)
                spinner.setSelection(i);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> objectLoader) {
        adapter.changeCursor(null);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())   {
            case R.id.addSight:
                new AlertDialog.Builder(getActivity())
                        .setTitle("??????? ????????????? ???????")
                        .setView(getActivity().getLayoutInflater().inflate(R.layout.add_dialog, null))
                        .setPositiveButton("???????", this).create().show();
                break;
            case R.id.deleteSight:
                CSQLiteOpenHelper.getHelper(getActivity()).delete(CSQLiteOpenHelper.TABLE_SIGHTS,
                        spinner.getSelectedItemId());
                update();
                break;
    }
}

    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        CSQLiteOpenHelper.getHelper(getActivity()).addSight(
                ((EditText) ((AlertDialog) dialogInterface).findViewById(R.id.text1)).getText().toString(),
                ((EditText) ((AlertDialog) dialogInterface).findViewById(R.id.text2)).getText().toString()
        );
        update();
    }

    public void setOnItemSelectedListener(Spinner.OnItemSelectedListener listener) {
        spinner.setOnItemSelectedListener(listener);
    }
}




Java Source Code List

com.Andryyo.ArchPad.CArrow.java
com.Andryyo.ArchPad.CShot.java
com.Andryyo.ArchPad.MainActivity.java
com.Andryyo.ArchPad.archeryFragment.CArcheryFragment.java
com.Andryyo.ArchPad.archeryFragment.CCurrentEndView.java
com.Andryyo.ArchPad.archeryFragment.CDistanceTemplate.java
com.Andryyo.ArchPad.archeryFragment.CDistance.java
com.Andryyo.ArchPad.archeryFragment.CRoundTemplate.java
com.Andryyo.ArchPad.archeryFragment.CRound.java
com.Andryyo.ArchPad.archeryFragment.IOnShotAddListener.java
com.Andryyo.ArchPad.archeryFragment.?EndsCounterView.java
com.Andryyo.ArchPad.database.CSQLiteOpenHelper.java
com.Andryyo.ArchPad.note.CNoteCreateActivity.java
com.Andryyo.ArchPad.note.CNotesFragment.java
com.Andryyo.ArchPad.sight.CSightSelectFragment.java
com.Andryyo.ArchPad.sight.?SightPropertiesFragment.java
com.Andryyo.ArchPad.start.CArrowSelectView.java
com.Andryyo.ArchPad.start.CColorSelectView.java
com.Andryyo.ArchPad.start.CRoundSelectView.java
com.Andryyo.ArchPad.start.CStartFragment.java
com.Andryyo.ArchPad.start.CTargetSelectView.java
com.Andryyo.ArchPad.start.IOnFragmentSwapRequiredListener.java
com.Andryyo.ArchPad.statistics.CBorderedTextView.java
com.Andryyo.ArchPad.statistics.CRecordViewFragment.java
com.Andryyo.ArchPad.statistics.CStatisticsFragment.java
com.Andryyo.ArchPad.statistics.IOnUpdateListener.java
com.Andryyo.ArchPad.target.CEditableTargetView.java
com.Andryyo.ArchPad.target.CRing.java
com.Andryyo.ArchPad.target.CTargetView.java
com.Andryyo.ArchPad.target.CTarget.java
com.Andryyo.ArchPad.target.CZoomableTargetView.java