我有延伸的F類公共類A訪問時,類A有一個方法Aa.Then我有一個公共類B,其具有內部BB的公共方法BB I有一個對象k A類和D類實現接口E。在類DI中不能訪問k.Aa。爲什麼?好心幫助方法不能從嵌套類
package com.example.sreeharsh.layoutcreate;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
public class LDObservableScrollView extends ScrollView {
private MainActivity.LDObservableScrollViewListener scrollViewListener = null;
public LDObservableScrollView(Context context) {
super(context);
}
public LDObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public LDObservableScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollViewListener(MainActivity.LDObservableScrollViewListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
@Override
protected void onScrollChanged(int x, int y, int oldx, int oldy) {
super.onScrollChanged(x, y, oldx, oldy);
if(scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
}
}
}
package com.example.sreeharsh.layoutcreate;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
public interface LDObservableScrollViewListener {
void onScrollChanged(LDObservableScrollView scrollView, int x, int y, int oldx, int oldy);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LDObservableScrollView scroll=new LDObservableScrollView(this);
final LinearLayout layout =new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
final LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lparams.setMargins(0, 10, 0, 10);
lparams.gravity=Gravity.CENTER;
int i;
for(i=0;i<5;i++) {
ImageView imView = new ImageView(this);
imView.setLayoutParams(lparams);
Drawable new_image = getResources().getDrawable(R.drawable.rakthasakshi);
imView.setBackgroundDrawable(new_image);
layout.addView(imView, lparams);
}
scroll.addView(layout);
setContentView(scroll);
class DetectHere implements LDObservableScrollViewListener {
scroll.setScrollViewListener(this); //******* here cannot access the method setScrollViewListener ..
@Override
public void onScrollChanged(LDObservableScrollView scrollView, int x,
int y, int oldx, int oldy) {
// TODO Auto-generated method stub
if ((scrollView.getHeight() + y) >= layout.getHeight()) {
ImageView imView = new ImageView(MainActivity.this);
imView.setLayoutParams(lparams);
Drawable new_image = getResources().getDrawable(R.drawable.rakthasakshi);
imView.setBackgroundDrawable(new_image);
layout.addView(imView, lparams);
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
你能不能張貼一些代碼來說明問題類型
A
? – Bubletan我已經給出了整個代碼 –
你可以用實際的類名更新你的問題,所以我們可以找出你在問什麼? – nasch