android-da ishlamasligi kerak bo'lgan retrofit yordamida api chaqirish

Men ta'limni takomillashtirish uchun demo-ilovada ishlayapman, men ilovani takomillashtirishni qo'lladim va asta-sekin ketdim. Men tugmachani bosganimda @onclick annotatsiyasini ishlatganman, ammo hech qachon bajarilmaydi. Kimdir miyadan noto'g'ri ekanligini ayta oladimi?

 void getContacts() {
ApiInterface apiService =
        ApiClient.getClient().create(ApiInterface.class);
Call call = apiService.getContacts();
call.enqueue(new Callback() {
    @Override
    public void onResponse(Call call, Response response) {
        System.out.print("RESPONES---------------->" + response.body().toString());
        List movies = response.body().getContacts();
        Log.d(TAG, "Number of movies received: " + movies.size());
       // recyclerView.setAdapter(new MoviesAdapter(movies, R.layout.list_item_movie, getApplicationContext()));
    }

    @Override
    public void onFailure(Call call, Throwable t) {
        Log.e(TAG, t.toString());
    }
});

}

**

1
@ siva35 - tahrirlashda ilova qilingan. Iltimos, tekshiring
qo'shib qo'ydi muallif concentrate H2SO4, manba
Menga kursatilgan binoda qanday xatolik bor.
qo'shib qo'ydi muallif concentrate H2SO4, manba
Sizning graderingiz ....?
qo'shib qo'ydi muallif siva35, manba
qo'shib qo'ydi muallif siva35, manba
Annotatsiya qo'shishProcessor com.jakewharton: butterknife-compiler: 8.5.1 '
qo'shib qo'ydi muallif siva35, manba

6 javoblar

Gradlega annotationProcessor qo'shing va grader va loyihani qayta tiklang:

annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

Sizning kassangizda shunday bo'ladi:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.jakewharton:butterknife:8.5.1'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
2
qo'shib qo'ydi

Men butterknifning eski versiyasini @Bind annotatsiyasidan foydalanib, yaxshi ishlayapman, degandagi tugma ichidagi no'xat turini o'zgartirdim va u juda yaxshi ishladi.

compile 'com.jakewharton:butterknife:7.0.1'
0
qo'shib qo'ydi
U ajoyib ish! Lekin u ham eng yangi versiyasi bilan ishlashi kerak. Yangi versiyalarda bir qancha o'zgarishlar va tuzatish kiritildi: github.com/JakeWharton/ butterknife/blob/master/CHANGELOG.md Uni tushunishga urinib ko'ring, lekin sizning asosiy muammolaringiz graderga bog'liqligi edi;)
qo'shib qo'ydi muallif miljon, manba

kodingiz quyida keltirilgan bo'lishi kerak.

private static final String TAG = MainActivity.class.getSimpleName();
    @BindView(R.id.btn_1)
    Button button;
    @BindView(R.id.lv_contacts)
    RecyclerView lv_contacts;

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

    @OnClick(R.id.btn_1)
    public void buttonclick() {
        button.setText("Clicked!");
    }
0
qo'shib qo'ydi
hech qanday o'zgarishlar yo'q ..! Siz yozgan xuddi shu kod.!
qo'shib qo'ydi muallif concentrate H2SO4, manba

Buni matn ko'rinishida qo'shishga harakat qilib ko'rishingiz mumkin

android:onClick="buttonclick"

shuning uchun shunday bo'ladi:

   <button
    android:id="@+id/btn_1"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:onClick="buttonclick"
    android:text="Get Contacts"
    android:textSize="20dp"
    android:layout_alignParentTop="true" />
0
qo'shib qo'ydi
        ## In your java code use: ##

        @InjectView(R.id.btn_1)
        Button button;

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


            }

            @OnClick(R.id.btn_1)
            void submitButton(View view) {
                if (view.getId() == R.id.btn_1) {

                    Toast.makeText(this, "Click", Toast.LENGTH_SHORT).show();
                }
            }

    ## in your activity_main.xml : ##

    


        <button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/btn_1"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="59dp"
            android:layout_marginStart="59dp"
            android:layout_marginTop="132dp"
            android:onClick="submitButton"/>
    

## in build.gradle file(app) ##

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.jakewharton:butterknife:6.1.0'
}
0
qo'shib qo'ydi
"InjectView" ni qo'shganimda, "belgini o'chira olmaydi".
qo'shib qo'ydi muallif concentrate H2SO4, manba
mening magistrimni tekshirib ko'rsam bo'ladimi? yo'qolgan narsa bormi?
qo'shib qo'ydi muallif concentrate H2SO4, manba
build.gradle-ga bog'liq barcha bog'liqliklarni qo'shganmisiz?
qo'shib qo'ydi muallif user2852617, manba
@bind bilan oldingi ishimni tekshiring va harakat qilib ko'ring
qo'shib qo'ydi muallif user2852617, manba

onCreate: Button btn = (Button) findViewById(R.id.btn_1); btn.setOnClickListener(this); get an OnClickListener: Override/implement Methods... then in the OnClick: if(view.getId()==btn_1){ do sth. }

0
qo'shib qo'ydi