Created
September 13, 2017 09:20
-
-
Save mdsami/3e4c4516e355cf05075013a23a23a5ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.stccon.spiner; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.graphics.Color; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.ArrayAdapter; | |
import android.widget.Button; | |
import android.widget.Spinner; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
Spinner sp1; | |
Button btnSub; | |
SharedPreferences sharedPreferences ; | |
int sp1Value; | |
ArrayAdapter dataAdapter; | |
String[] sp_arr = {"খুব ভাল ", "ভাল ","মোটামুটি", "দূর্বল "}; | |
int[] sp_arr_no = {1,2,3,4}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
sp1 = (Spinner) findViewById(R.id.sp); | |
sharedPreferences = getSharedPreferences("spinner", Context.MODE_PRIVATE); | |
sp1Value = sharedPreferences.getInt("sp", 0); | |
dataAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,sp_arr); | |
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | |
sp1.setAdapter(dataAdapter); | |
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
@Override | |
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long arg3) { | |
((TextView) arg0.getChildAt(0)).setTextColor(Color.parseColor("#000000")); | |
// get_status = Work_Status_Name.get(pos); | |
sp1Value = sp_arr_no[pos] ; | |
Log.e("value","pos"+sp1Value); | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> arg0) { | |
} | |
}); | |
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
@Override | |
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { | |
String value = sp_arr[i]; | |
Log.e("spinner value", value); | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> adapterView) { | |
} | |
}); | |
btnSub = (Button) findViewById(R.id.btnSub); | |
btnSub.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//String sp1Value = sp.getText().toString(); | |
SharedPreferences.Editor editor = sharedPreferences.edit(); | |
editor.putInt("sp1",sp1Value); | |
editor.commit(); | |
// Log.e("test", sp12Value+"->"+sp13Value); | |
Intent i = new Intent(MainActivity.this, MainActivity.class); | |
startActivity(i); | |
Toast.makeText(getApplicationContext(), | |
"All Data Successfully Save ", | |
Toast.LENGTH_LONG).show(); | |
finish(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment