i have made some code, but now its to long and i want to separate it in different class in one java file. What ever i can try there is always app crash on start up or Source not found. In this case there is method on one class and i want to call it in main class to display in textview but source not found error occur.
package com.valchev.avilight;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends ListActivity {
public DirShow dirShow = new DirShow();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String s = "Blah Blah!";
dirShow.myDirShow(s);
}
//Settings layer
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
class DirShow extends MainActivity {
public void myDirShow(String s) {
s = "blah!";
TextView text = new TextView(this);
text = (TextView)findViewById(R.id.path);
text.setText(s);
}
}
You can not do that. You are trying to create
Activityobject yourself. If you want to start newActivityyou should useContext.startActivity. Here is a bit more information about how activities work. And btw you should not try to start two activities in the same time. One activity equals (roughly said) one user interface screen. If you want to open new user interface then you can start new activity.I don’t really seen any reason for
DirShowto extendsActivity, if you really insist on different class you can passMainActivityas second argument tomyDirShowor pass it in the contstructor and keep it as a member variable in DirShow. Maybe there is a better way but my Java is not really that good.