class example extends Activity {
class2 btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = new Class2();
btn.color(this);
}
}
// Another class(class2)
public class class2 {
protected void color(Activity mActivity) {
LinearLayout layoutcolor = (LinearLayout) mActivity.findViewById(R.id.linearcolor);
// some code
}
}
更新:サンプルを作成しましたが、それは私にとってはうまくいきます。実装を確認してください。または完全なコードを投稿してください。
package com.example.test;
import android.app.Activity;
import android.app.ListActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class sampleMediaPlayer extends ListActivity {
// Toast mToast;
private TextView selection;
class2 btn;
private static final String[] items = { "Computer Hardware", "Featured", "Information Technology",
"Software", "Technical"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
items);
setListAdapter(adapter);
btn = new class2();
btn.color(this);
}
public void onListItemClick(ListView parent, View v, int position, long id) {
selection.setText(items[position]);
}
// Another class(class2)
public class class2 {
protected void color(Activity mActivity) {
ListView layoutcolor = (ListView) mActivity.findViewById(android.R.id.list);
layoutcolor.setBackgroundColor(Color.GREEN);
Log.i("NIMISH", "HEy ");
}
}
}