2016-10-21 4 views
0

앱이있어서 갑자기 내 사용자 인터페이스가 공유 버튼 작동 및 옵션 메뉴를 작동하지 않게되었지만 이상한 이유로 버튼이 작동하지 않고 클릭하지 않거나 뭐든지해라. 아마 내 OptionsMenu 클래스의 확장 때문입니까? 왜 그런지 몰라? 이런 일이 종종 발생하지만 프로젝트를 새로 만들지 만 사용하지는 않습니다. 여기내 UI가 작동하지 않습니다 (버튼)

package com.mycompany.myapp; 
import android.app.*; 
import android.os.*; 
import android.widget.Button; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.EditText; 
import android.widget.AdapterView; 
import android.widget.TextView; 
import java.io.*; 
import android.content.*; 
import android.view.*; 
import android.media.*; 
import javax.security.auth.*; 
import android.util.*; 
import android.widget.AdapterView.*; 
import java.net.*; 
import org.apache.http.util.*; 
import android.webkit.*; 
import java.text.*; 
import android.graphics.*; 
import android.widget.TextView.*; 
import android.text.*; 
import android.widget.ActionMenuView.*; 
import android.view.MenuItem.*; 
import android.widget.*; 
import android.content.Intent; 
import android.net.*; 
import java.util.*; 
import java.nio.channels.*; 
import java.nio.*; 
import android.*; 
public class MainActivity extends OptionsMenu 
{ 
private MusicPlayer musicPlayer; 
private String pos = ""; 
private FileManager fm; 
private BlueTheme BlueTheme; 
private PinkTheme PinkTheme; 
private Downloader downloader; 
private EditTextCustomizable etc; 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 
    musicPlayer = new MusicPlayer(new MediaPlayer()); 
    fm = new FileManager(this,this); 
    BlueTheme = new BlueTheme(this,this ,fm); 
    PinkTheme = new PinkTheme(this,this,fm); 
    etc = new EditTextCustomizable(this , BlueTheme , PinkTheme); 
    etc.customize(); 
    Button rewind = (Button)findViewById(R.id.rewind); 
    rewind.setText("<"); 
    Button fwd = (Button)findViewById(R.id.fwd); 
    fwd.setText(">"); 
    ListView downloadsList = (ListView) findViewById(R.id.downloads); 
    downloadsList.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 
      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3){ 
       ListView downloadsList = (ListView) findViewById(R.id.downloads); 
       pos = downloadsList.getItemAtPosition(position).toString(); 
       musicPlayer.InitPlay(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/" + pos); 
      }}); 
} 
public void Play(View view){ 
    musicPlayer.Play(); 
    EditText search = (EditText)findViewById(R.id.search); 
    musicPlayer.SearchResult(search.getText().toString()); 
} 


public void Pause(View view){ 
    musicPlayer.Pause(); 
} 

public void Stop(View view){ 
    musicPlayer.Stop(); 
    } 
public void Rewind(View view){ 
    musicPlayer.Rewind(); 
} 

public void Fwd(View view){ 
    musicPlayer.Fwd(); 
} 

public void onDownloadClick(View view){ 
    EditText bar = (EditText)findViewById(R.id.search); 
    String downloadFile = bar.getText().toString(); 
    downloader.DownloadURL(downloadFile); 
} 
} 

그리고 내가 AppCompatActivity를 사용하고 있지 않다 활동 메모를 확장하고있는 OptionsMenu 클래스는 여기 내 MainActivity 클래스가 있습니다.

package com.mycompany.myapp; 
import android.view.*; 
import android.app.*; 
import android.net.*; 
import java.util.*; 
import android.widget.ListView; 
import android.content.*; 
import java.io.*; 
import android.widget.*; 
import android.*; 
public class OptionsMenu extends Activity 
{ 
private MusicPlayer musicPlayer; 
private FileManager fm; 
private BlueTheme blueTheme; 
private PinkTheme pinkTheme; 
private final int blue = Menu.FIRST; 
private final int pink = blue + 1; 
private int items = 0; 

@Override 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    fm = new FileManager(this,this); 
    blueTheme = new BlueTheme(this,this,fm); 
    pinkTheme = new PinkTheme(this,this,fm); 
    fm.ListFiles(); 
    menu.clear(); 
    MenuInflater inflator = getMenuInflater(); 
    inflator.inflate(R.menu.sidebar_menu, menu); 
    SubMenu subMenu = menu.addSubMenu("Themes"); 
    subMenu.add(0 , blue , 0 , "Blue"); 
    subMenu.add(0, pink , 1, "Pink"); 
    items = subMenu.getItem().getItemId(); 

    // tool bar menu 
    ArrayList<Uri> al = new ArrayList<Uri>(); 
    ArrayList<Uri> emailAl = new ArrayList<Uri>(); 
    MenuItem mi = menu.findItem(R.id.searchable); 
    MenuItem share = menu.findItem(R.id.share); 
    mi.setIcon(android.R.drawable.ic_search_category_default); 
    SearchView searchView = (SearchView) menu.findItem(R.id.searchable).getActionView(); 
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 
    ShareActionProvider sap = (ShareActionProvider) share.getActionProvider(); 
    Intent intentShare = new Intent(Intent.ACTION_SEND_MULTIPLE); 
    Intent intentEmail = new Intent(Intent.ACTION_SEND_MULTIPLE); 
    intentShare.setType("audio/mp3"); 
    intentEmail.setType("audio/mp3"); 
    Uri uri = null; 
    Uri uriEmail = null; 
    //FileInputStream in = null; 
    //FileOutputStream out = null; 
    //try{ 
    // for(File file : downloads){ 
    // uri = Uri.fromFile(file); 
    //  in = new FileInputStream(file); 
    //  File outFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), file.getName()); // IMPORTANT! You need to create your file object separately, so you can then pass it to intent as well.. 
    //  out = new FileOutputStream(outFile); 
    // byte[] buf = new byte[1024]; 
    //  int len; 
    //  while ((len = in.read(buf, 0, buf.length)) != -1){ 
    //  out.write(buf, 0, len); 
    //   } 

    //   in.close(); 
    //   out.flush(); 
    //   out.close(); 
    //   uriEmail = Uri.fromFile(outFile); // Here you passed the parent directory file.. Pass newly created file object .. 
    //   al.add(uri); 
    //   emailAl.add(uriEmail); 

    //   } 

    //   } catch(IOException e){ 
    //    e.printStackTrace(); 
    //   } 
    //for(File file : fm.GetDownloadFiles()){ 
    // uriEmail = Uri.fromFile(fm.exportFile(file)); 
    //} 
    emailAl.add(uriEmail); 
    intentShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM,al); 
    intentEmail.putParcelableArrayListExtra(Intent.EXTRA_STREAM,emailAl); 
    intentEmail.putExtra(Intent.EXTRA_SUBJECT , "Subject"); 
    intentEmail.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    sap.setShareIntent(intentShare); 
    sap.setShareIntent(intentEmail); 
    return super.onCreateOptionsMenu(menu); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 

    switch(item.getItemId()){ 
     case R.id.playlist: 

      break; 
     case blue: 
      blueTheme.Blue(); 
      break; 

     case pink: 
      pinkTheme.Pink(); 
      break; 
     case R.id.muteoption: 
      musicPlayer.MuteVolume(); 
      break; 
     case R.id.unmuteoption: 
      musicPlayer.UnMuteVolume(); 
      break; 

     default: 
      return super.onOptionsItemSelected(item); 
      // TODO: Implement this method 
    } 
    return super.onOptionsItemSelected(item); 
} 
} 

요청하면 더 많은 코드를 게시 할 수 있습니다. 명확하지 않은 경우 그리고 충분한 여기

편집 당신에게

감사합니다 가능하면

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:elevation="4dp" 
    android:showAsAction="always" 
    android:windowActionBar="false" 
    android:theme="@android:style/Theme.Holo.Light" 
    /> 

<TextView 
    android:id="@+id/downloadsTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    /> 
<Button 
    android:id="@+id/downloadButton" 
    android:text="@string/downloadButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:onClick="onDownloadClick" 
/> 

<EditText 
    android:id="@+id/search" 
    android:hint="Do something" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_below="@id/downloadButton" 
    android:background="@android:color/transparent" 
    android:paddingBottom="20dp" 
    android:paddingTop="20dp"/> 

<Button 
    android:id="@+id/pause" 
    android:text="@string/pause" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:onClick="Pause" 
    android:layout_centerInParent="true" 
    android:layout_below="@id/search" 
    /> 

<Button 
    android:id="@+id/play" 
    android:text="@string/play" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:onClick="Play" 
    android:layout_toRightOf="@id/pause" 
    android:layout_below="@id/search"/> 

<Button 
    android:id="@+id/stop" 
    android:text="@string/stop" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:onClick="Stop" 
    android:layout_toLeftOf="@id/pause" 
    android:layout_below="@id/search"/> 

<Button 
    android:id="@+id/rewind" 
    android:text="@string/rewind" 
    android:layout_height="wrap_content" 
    android:layout_width="50dp" 
    android:onClick="Rewind" 
    android:layout_toLeftOf="@id/stop" 
    android:layout_below="@id/search"/> 

<Button 
    android:id="@+id/fwd" 
    android:text="@string/fwd" 
    android:layout_height="wrap_content" 
    android:layout_width="50dp" 
    android:onClick="Fwd" 
    android:layout_toRightOf="@id/play" 
    android:layout_below="@id/search"/> 

<ListView 
    android:id="@+id/downloads" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/rewind" 
    /> 
</RelativeLayout> 
+0

대부분의 버튼을 onClickListener로 설정할 수 없습니다. 레이아웃 XML에 설정되어 있습니까? 그렇지 않은 경우 문제 일 수 있습니다. –

+0

예 모든 버튼은 OnClick을 사용하여 XML 레이아웃에 설정되었지만 이전에는 작동했지만 갑자기 중지되었습니다. –

+0

OnItemClickListener도 작동하지 않으며 코드가 옳다는 것을 알고 있습니다. (무례한 것은 아닙니다. 나는 초보자입니다.)하지만 지금은 아무런 클릭이나 아무것도하지 않았습니까? –

답변

0

는 레이아웃 XML을 붙여 레이아웃 XML을한다 재 편집합니다. 그것은 뭔가 (어쩌면 일부 부모보기) 포커스를 중단, 그래서 자식보기 단추를 포커스를 얻을 수 없습니다 발생하는 것 같아요.

+0

레이아웃 XML을 게시했습니다 도움을 주셔서 감사합니다 BTW –

관련 문제