|  | 
	                
 
 
  
    | 
        
        Android สอบถามการเก็บค่าจาก Spinner ที่เลือกลง Database (PHP/MySQL)     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | อยากเก็บข้อมูลที่เลือกจาก spinner เข้าไปใน database ต้องทำยังไงเหรอคะ? หรือว่าพอจะมีบทความที่เกี่ยวข้องรึเปล่า
 
 คือตอนนี้แสดงข้อมความตาม list ที่เลือกได้แล้ว และอยากจะเก็บ list ที่เลือกนี้ลง database อะคะ
 เหมือนจะต้องเอาค่า sharepreference มาเกี่ยวด้วย เพราะต้องล็อคอินเข้ามาก่อน ถึงจะมาเลือก spinner ได้
 แล้วค่อยเก็บข้อมูลอีกทีอะคะ เพื่อที่จะรู้ว่า user คนนี้ เลือก list ไหน ทำนองนี้อะคะ
 
 รบกวนผู้รู้ด้วยนะคะ, ขอบคุณค่ะ :)
 
 Code (Java)
 
 package com.example.hello_oppa;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;
import twitter4j.Twitter;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;
import com.example.hello_oppa.adapter.CategoryArtistAdapter;
import com.example.hello_oppa.model.Artist_Model;
import com.example.hello_oppa.service.JSONParser;
import com.example.hello_oppa.twitter.ConstantValues;
import com.example.hello_oppa.twitter.TwitterUtil;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class ChooseArtistActivity extends Activity {
	
	Spinner category_artist;
	TextView ArtistName;
	
	private ArrayList<Artist_Model> artist_data;
	private Artist_Model model = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_chooseartist);
		// custom my action bar
		ActionBar actionbar = getActionBar();
		actionbar .setTitle("ADD NEW ARTIST");
		// back navigation
		actionbar.setDisplayHomeAsUpEnabled(true);
		// hide icon app
		getActionBar().setDisplayShowHomeEnabled(false);
		
		ArtistName = (TextView) findViewById(R.id.ArtistName);
		
		Button BTNchoose = (Button) findViewById(R.id.BTNchooseArtist);
		BTNchoose.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ChooseArtistActivity.this, MainActivity.class);
				startActivity(intent);
			}
		});
		
//		//login twitter
//		Uri uri = getIntent().getData();
//	    String verifier = uri.getQueryParameter(ConstantValues.URL_PARAMETER_TWITTER_OAUTH_VERIFIER); 
// 
//	    TwitterGet get=new TwitterGet();
//	    get.execute(verifier);
		
		//
		artist_data = new ArrayList<Artist_Model>();
//		String url = "http://www.leveltistweb09.com/Hello_Oppa/get_artist.php";
		String url = "http://su13540254.2th.asia/Hello_Oppa/get_artist.php";
		JSONParser json = new JSONParser();
		String dataJSON = json.makeHttpRequest(url, JSONParser.methodGet, null);
		JSONArray jsArr;
		JSONObject jsOBJ;
		JSONObject jsOBJ2;
		try {
			jsOBJ = new JSONObject(dataJSON);
			jsArr = jsOBJ.getJSONArray("artist");
			for (int i = 0; i < jsArr.length(); i++) 
			{
				jsOBJ2 = jsArr.getJSONObject(i);
				int artist_id = jsOBJ2.getInt("artist_id");
				String artist_name = jsOBJ2.getString("artist_name");
				String artist_tag = jsOBJ2.getString("artist_tag");
				String artist_img = jsOBJ2.getString("artist_img");
				model = new Artist_Model(artist_id, artist_name, artist_tag, artist_img);
				artist_data.add(model);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// spinner
		category_artist = (Spinner) findViewById(R.id.Spinartist);
		CategoryArtistAdapter myAdapter = new CategoryArtistAdapter(this, R.layout.item_dropdown, artist_data);
		category_artist.setAdapter(myAdapter);
		
		//setOnItemSelectedListener
		category_artist.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
		{	    
			@Override
		    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				String artist_name = artist_data.get(position).getArtist_name().toString();
			    ArtistName.setText(artist_name);
		    }
			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
			}	
		});
	
	}//end onCreate
}
 
 
 Tag : Mobile, MySQL, Android, JAVA
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2015-02-25 01:25:55 | By :
                          Bubufufu | View :
                          1887 | Reply :
                          3 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | โอเคค่ะ เดี๋ยวจะลองทำดูอีกทีนะคะ เพราะทำสมัครสมาชิกแล้วเก็บเข้า database ได้แล้ว
 
 ขอสอบถามอีกอย่างค่ะ แล้วถ้าเลือก list แล้วจะให้โชว์เป็นรูปภาพของ list ที่เลือก
 ระหว่างสร้าง array แล้วดึงภาพจาก array กับดึงภาพที่มีใน table ของ database อันไหนง่ายและเร็วกว่ากันอะคะ?
 คือตอนนี้เก็บภาพไว้ใน database กลัวว่าจะดึงภาพมาใช้ยากอะคะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-02-25 11:56:11 | By :
                            ฺBubufufu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | แสดงทีล่ะรูปน่าจะเร็วกกว่าครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-02-25 21:32:21 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |