3
Hello, I’m trying to call a new Activity through OnClick
in a TextView
, but when running the application generates a crash.
Here’s the Activity of from the one I’m trying to get through:
public class sdActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "TesteGigaservicesAPP";
//list view dos produtos
public ListView lv;
//list view adapter
ArrayAdapter<String> adapter;
//barra de busca
AutoCompleteTextView inputSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sd);
//produtos da busca
String[] produtos = {
"Produto 1",
"Produto 2",
"Produto 3",
"Produto 4",
"Produto 5"
};
lv = (ListView)findViewById(R.id.listaDProdutos);
inputSearch = (AutoCompleteTextView)findViewById(R.id.barradepesquisa);
//popula a lista
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, produtos);
lv.setAdapter(adapter);
//
//aciona a barra de buscas
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void beforeTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
sdActivity.this.adapter.getFilter().filter(cs);
}
@Override
public void afterTextChanged(Editable s) {
}
});
/*problemas de implementação*/
TextView ver = (TextView)findViewById(R.id.product_name);
ver.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(sdActivity.this, ProdutoActivity.class));
//teste para passar sob o elemento de uma view de layout
}
});
//botão que volta a página anterior
Button btVoltarUm = (Button)findViewById(R.id.btVoltarUm);
btVoltarUm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(sdActivity.this, MainActivity.class));
}
});
}
}
The item product_name
is in a separate layout file that is like list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Single ListItem -->
<!-- Nome do produto listado -->
<TextView
android:id="@+id/product_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testegigaservices.testegigaservices">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".sdActivity"
android:label="@string/pgBusca"
android:windowSoftInputMode="stateHidden"></activity>
<activity android:name=".produtoActivity"></activity>
</application>
"when running the application generates a crash" - The first step in this case is to consult the Log to see which error message and which line it was wrong on. You should take this error message and ask the question
– Isac
ok, from the logcat queries I will insert the logs on the next try.
– Jonathan Viana