이제 결과를 받아왔으니

적절하게 꾸며야지


27개의 Todo가 있다.


<!--TODO (1) Add a string stating that an error has occurred-->

strings.xml 부터 error 발생 시 보여줄 message 추가

<resources>
    <string name="app_name">GithubSearch</string>

    <string name="search">Search</string>

    <!--TODO (1) Add a string stating that an error has occurred-->
    <string name="error_message">
        Failed to get results. Please try again.
    </string>
</resources>


<!--TODO (2) Wrap the ScrollView in a FrameLayout-->
<!--TODO (3) Make the width and height of the FrameLayout match_parent-->
activity_main.xml 에 scrollview를 FrameLayout으로 감싸준다.

    <!--TODO (2) Wrap the ScrollView in a FrameLayout-->
    <!--TODO (3) Make the width and height of the FrameLayout match_parent-->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp">
            <TextView
                android:id="@+id/tv_github_search_results_json"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Make a search!"
                android:textSize="18sp" />
        </ScrollView>
    </FrameLayout> 


<!--TODO (4) Add a TextView to display an error message-->
<!--TODO (5) Set the text size to 22sp-->
<!--TODO (6) Give the TextView an id of @+id/tv_error_message_display-->
<!--TODO (7) Set the layout_height and layout_width to wrap_content-->
<!--TODO (8) Add 16dp of padding to the error display -->
<!--TODO (9) Use your strings.xml error message to set the text for the error message-->
<!--TODO (10) Set the visibility of the view to invisible-->
<!--TODO (11) Make this TextView a child of the FrameLayout that you added above-->

error message를 화면에 보여줄 수 있도록 Textview를 추가한다.

        <TextView
            android:id="@+id/tv_error_message_display"
            android:textSize="22sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:text="@string/error_message"
            android:visibility="invisible" /> 


<!--TODO (18) Add a ProgressBar to indicate loading to your users-->
<!--TODO (19) Give the ProgressBar an id of @+id/pb_loading_indicator-->
<!--TODO (20) Set the layout_height and layout_width to 42dp-->
<!--TODO (21) Set the layout_gravity to center-->
<!--TODO (22) Set the visibility of the ProgressBar to invisible-->
<!--TODO (23) Make this ProgressBar a child of the FrameLayout the you added above-->

처리되는 동안 표시 될 Progressbar를 추가한다.

        <ProgressBar
            android:id="@+id/pb_loading_indicator"
            android:layout_height="42dp"
            android:layout_width="42dp"
            android:layout_gravity="center"
            android:visibility="invisible" /> 


MainActivity를 수정한다.

순서상으로는 12(TextView 추가) 후 24(Progressbar 추가) 이나 xml을 먼저 정의 해 놓은 다음 처리했다.

// TODO (12) Create a variable to store a reference to the error message TextView
// TODO (24) Create a ProgressBar variable to store a reference to the ProgressBar

import android.widget.ProgressBar;
...
    // TODO (12) Create a variable to store a reference to the error message TextView
    private TextView mErrorMessageDisplay;
    // TODO (24) Create a ProgressBar variable to store a reference to the ProgressBar
    private ProgressBar mLoadingIndicator; 


// TODO (13) Get a reference to the error TextView using findViewById
// TODO (25) Get a reference to the ProgressBar using findViewById

onCreate method에 xml값과 변수를 매핑시킨다.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSearchBoxEditText = (EditText) findViewById(R.id.et_search_box);
        mUrlDisplayTextView = (TextView) findViewById(R.id.tv_url_display);
        mSearchResultsTextView = (TextView) findViewById(R.id.tv_github_search_results_json);

        // TODO (13) Get a reference to the error TextView using findViewById
        mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display);
        // TODO (25) Get a reference to the ProgressBar using findViewById
        mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator);
    } 


// TODO (14) Create a method called showJsonDataView to show the data and hide the error
// TODO (15) Create a method called showErrorMessage to show the error and hide the data

jsonData를 보여줄 method 추가, errorMessage를 보여줄 method 추가

    // TODO (14) Create a method called showJsonDataView to show the data and hide the error
    private void showJsonDataView() {
        // First, make sure the error is invisible
        mErrorMessageDisplay.setVisibility(View.INVISIBLE);
        // Then, make sure the JSON data is visible
        mSearchResultsTextView.setVisibility(View.VISIBLE);
    }


    // TODO (15) Create a method called showErrorMessage to show the error and hide the data
    private void showErrorMessage() {
        // First, hide the currently visible data
        mSearchResultsTextView.setVisibility(View.INVISIBLE);
        // Then, show the error
        mErrorMessageDisplay.setVisibility(View.VISIBLE);
    } 


// TODO (16) Call showErrorMessage if the result is null in onPostExecute       
// TODO (17) Call showJsonDataView if we have valid, non-null results

inner class인 GithubQueryTask 의 onPostExecute에 결과를 보여주도록 추가

        @Override
        protected void onPostExecute(String githubSearchResults) {
            if (githubSearchResults != null && !githubSearchResults.equals("")) {
                // TODO (17) Call showJsonDataView if we have valid, non-null results
                showJsonDataView();
                mSearchResultsTextView.setText(githubSearchResults);
            } else {
                // TODO (16) Call showErrorMessage if the result is null in onPostExecute
                showErrorMessage();
            }
        } 


// TODO (26) Override onPreExecute to set the loading indicator to visible

inner class인 GithubQueryTask 의 onPreExecute 재정의(onPostExecute아님)

        // TODO (26) Override onPreExecute to set the loading indicator to visible
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mLoadingIndicator.setVisibility(View.VISIBLE);
        } 


// TODO (27) As soon as the loading is complete, hide the loading indicator

loading이 끝나자마다 indicator를 숨기도록 처리

onPostExecute 의 최종 결과임

    @Override
    protected void onPostExecute(String githubSearchResults) {
        // TODO (27) As soon as the loading is complete, hide the loading indicator
        mLoadingIndicator.setVisibility(View.INVISIBLE);
       
        if (githubSearchResults != null && !githubSearchResults.equals("")) {
            // TODO (17) Call showJsonDataView if we have valid, non-null results
            showJsonDataView();
            mSearchResultsTextView.setText(githubSearchResults);
        } else {
            // TODO (16) Call showErrorMessage if the result is null in onPostExecute
            showErrorMessage();
        }
    } 



728x90
BLOG main image
"그게 뭐 어쨌다는 거냐?" 늘 누가 나에게 나에대한 말을할 때면 이말을 기억해라. by nobang

카테고리

nobang이야기 (1933)
Life With Gopro (7)
Life With Mini (79)
Diary (971)
너 그거 아니(do you know) (162)
난 그래 (159)
Study (290)
속지말자 (10)
Project (34)
Poem (15)
Song (0)
Photo (113)
낙서장 (45)
일정 (0)
C.A.P.i (2)
PodCast (0)
nobang (27)
고한친구들 (4)
recieve (0)
History (0)
android_app (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :