class BackgroundTask extends AsyncTask<Void, Void, String>
{
String target;

protected void onPreExecute(){
target = "주소 값";
}
@Override
protected String doInBackground(Void... params) {
try{
URL url = new URL(target);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String temp;
StringBuilder stringBulider = new StringBuilder();
while((temp = bufferedReader.readLine()) != null)
{
stringBulider.append(temp + " ");
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return stringBulider.toString().trim();
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public void onProgressUpdate(Void... values)
{
super.onProgressUpdate();
}
@Override
public void onPostExecute(String result)
{
try{
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.getJSONArray("response");
int count = 0;
String location, state, userID;
while(count < jsonArray.length())
{
JSONObject object = jsonArray.getJSONObject(count);
location = object.getString("location");
state = object.getString("state");
userID = object.getString("userID");
Map map = new Map(location, state, userID);
mapList.add(map);
count++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

위의 소스로 프래그먼트에 db값을 받아오는데요.

프래그먼트의 onActivityCreated(Bundle e)에서


test = new BackgroundTask();
test.execute();

mapList = new ArrayList<Map>();

이렇게 해준 후 실험용으로 데이터베이스를 불러왔는지 보기위해 (lo0은 버튼)

lo0.setText(mapList.get(0).state);를 하면 모바일에서 프래그먼트를 누름과 동시에 꺼지구요


lo0에 온클릭 리스너를 준 후 그 안에서 mapList를 불러오면 프래그먼트 누름 -> 버튼 누름 하면 값을 받아오더라구요


프래그먼트가 열림과 동시에 버튼의 속성들이 데이터베이스값에 따라 변화되었으면하는데 데이터베이스를 접속하기 전에 값을 가져오려해서 에러가 나는 것같아요.


이런경우에는 어떤식으로해야 바로 값을 가져와서 프래그먼트 클릭과 동시에 버튼들의 속성이 정의될까요?


사진은 버튼 클릭 이벤트 없이 바로 불러왔을 때 로그캣입니다.

viewimage.php?id=3dafdf21f7d335ab67b1d1&no=29bcc427bd8477a16fb3dab004c86b6f858e30ebd71dc5042adb20366504c73318f73b6f99a68cf9a288bd02a100faafc69aa5364c370f4f96427f52f49a32a82d

횡설수설 죄송합니다.